In high-frequency market analysis at Two Sigma and Tower Research, analysts monitor the endurance of bid prices across streaming quotes. The span of an instrument's price today is defined as the maximum number of consecutive trading days (starting today and going backwards) for which the price of the stock was less than or equal to today's price.
Design an online streaming class StockSpanner that processes quotes one by one.
Your Task
Implement the StockSpanner class:
StockSpanner(): Initializes the object with an empty quote history.next(price: int) -> int: Collects today's market price and returns the span of that price.Constraints
next.Examples
spanner = StockSpanner()
spanner.next(100) # returns 1
spanner.next(80) # returns 1
spanner.next(60) # returns 1
spanner.next(70) # returns 2 (70 >= 60, span = [60, 70])
spanner.next(60) # returns 1
spanner.next(75) # returns 4 (75 >= [60, 70, 60, 75])
spanner.next(85) # returns 6