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
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution