901. Online Stock Span

Practice Online Stock Span for free on NudgeCode: Medium, Stack pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Prices of a stock arrive one day at a time. For each new price, return its span: the number of consecutive days, ending today and going backwards, on which the price was less than or equal to today's price.

Each test is a list of operations and their arguments; the expected output lists what each call returns (null for calls that return nothing).

Example

["StockSpanner","next","next","next","next","next","next","next"]
[[],[100],[80],[60],[70],[60],[75],[85]]
->  [null,1,1,1,2,1,4,6]

Constraints