Span of Each Day
prices holds a stock's price on consecutive days. The span of day i is the number of consecutive days ending on day i (day i included, counting backwards without a gap) whose price is less than or equal to prices[i].
Return the list of spans, one per day, in day order. The span of the first day is always 1. Return an empty list for an empty prices.
Example 1
prices [100,80,60,70,60,75,85]
returns [1,1,1,2,1,4,6]
Day 3 (price 70) covers itself and the 60 before it; day 6 (price 85) covers all days back to the 80 on day 1 but not the 100 on day 0.
Example 2
prices [1,2,3,4]
returns [1,2,3,4]
Each day is higher than every day before it, so each span reaches back to the start.
Constraints
0 <= len(prices) <= 100-1000 <= prices[i] <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Stacks and queues problems
- Ticket Line Finish OrderEasy
- Typing With Home and EndEasy
- Where cd LandsEasy
- Balanced Outside QuotesMedium
- Browser Back and ForwardMedium
- Convoys at the GateMedium
- Daily TemperaturesMedium
- Decode StringMedium