Design an algorithm that collects daily price quotes for some stock and returns the span of that stock's price for the current day. The span of the stock's price in one day is the maximum number of consecutive days (starting from that day and going backward) for which the stock price was less than or equal to the price of that day. Implement the StockSpanner class: - StockSpanner() Initializes the object of the class. - int next(int price) Returns the span of the stock's price given that today's price is price.
Example 1
Input: operations = ["StockSpanner","next","next","next","next","next","next","next"], arguments = [[],[100],[80],[60],[70],[60],[75],[85]]
Output: [null,1,1,1,2,1,4,6]
Explanation: Each span counts today plus the unbroken run of earlier days with a price ≤ today's. 70 covers [60,70] → 2. 75 covers [60,70,60,75] → 4. 85 covers [80,60,70,60,75,85] → 6, stopping at 100.
Example 2
Input: operations = ["StockSpanner","next","next","next"], arguments = [[],[10],[20],[30]]
Output: [null,1,2,3]
Explanation: The price rises every day, so each day covers all earlier days: 1, 2, 3.
Example 3
Input: operations = ["StockSpanner","next"], arguments = [[],[5]]
Output: [null,1]
Explanation: The first day has no history, so its span is 1.
Keep a stack of previous days that are strictly greater than everything after them. When a new price arrives, absorb (pop) all earlier days with price <= today, summing their spans — those days are now dominated by today.
Run checks all cases above. Submit evaluates all test cases.