157. Stock Span
Challenge1000 ms256 MBSolved by 0%
The span of a day's price is how many consecutive days up to and including that day had a price less than or equal to it.
Read n daily prices and print the span for each, separated by single spaces.
For [100, 80, 60, 70, 60, 75, 85] the spans are 1 1 1 2 1 4 6.
Constraints - `1 ≤ n ≤ 200000` - `0 ≤ price ≤ 1000000000`
Input
The first line contains an integer n.
The second line contains n space-separated integers.
Output
Print n integers on ONE line, separated by single spaces, the span for each day.
Input7
100 80 60 70 60 75 85
Output1 1 1 2 1 4 6
Noteis the worked example from the statement
Input1
50
Output1
Noteis a single day, whose span is always 1
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.