Problem 75 of 75

Online Stock Span

MediumNot solved yetInterview me on this
Before you code · which pattern fits?

The problem

Implement StockSpanner: next(price) returns the span of today's price — the number of consecutive days (ending today, going backward) the price was less than or equal to today's price.

next(100)=1, next(80)=1, next(60)=1, next(70)=2, next(60)=1, next(75)=4, next(85)=6

Your solution runs against 1 unit tests, including edge and large-value cases.

Loading...

Test console · 1 unit tests

Submit your code to run it against all 1 unit tests. Results appear here.

JavaScript, TypeScript & Python run sandboxed in your browser; other languages run on the execution server. Your code is saved locally as you type.

Hint

Reference solution

Video explanation

Online Stock Span, explainedNeetCode