We’re preparing your current view and syncing the latest data.
Design an online algorithm to calculate the span of stock's price for all days. The stock span is the number of consecutive days leading up to and including the current day for which the stock price was less than or equal to the current day's price.
Implement the StockSpanner class:
Example: Input: ["StockSpanner", "next", "next", "next", "next", "next", "next", "next"] [[], [100], [80], [60], [70], [60], [75], [85]] Output: [null, 1, 1, 1, 2, 1, 4, 6]
For each query, the input is a single integer price representing the price of the stock for the current day.
Return an integer representing the span of stock price for the current day.
1 <= price <= 10^5 At most 10^4 calls will be made to next.
Example 1
Input
['next(100)', 'next(80)', 'next(60)', 'next(70)', 'next(60)', 'next(75)', 'next(85)']
Output
[1, 1, 1, 2, 1, 4, 6]
Explanation
The spans for the days are 1 (only the first day), 1 (since 80 <= 80 only 1 day), 1 (60 only), 2 (70 and 60), 1 (60 only), 4 (75, 60, 70, 60), 6 (85 and previous 5 days).