#K83232. Daily Temperatures
Daily Temperatures
Daily Temperatures
Given a sequence of daily temperatures, your task is to determine for each day how many days one has to wait until a warmer temperature occurs. If there is no future day with a warmer temperature, then output 0 for that day.
Formally, given an array ( T[0\dots n-1] ) containing the temperatures, for each index ( i ) you need to find the smallest index ( j ) such that ( j > i ) and ( T[j] > T[i] ). The answer for day ( i ) is ( j - i ), or 0 if no such ( j ) exists.
For example, if ( n = 4 ) and ( T = [73, 74, 75, 71] ), the answer is [1, 1, 0, 0].
inputFormat
The first line contains a single integer ( n ) (( 1 \leq n \leq 10^5 )), the number of days. The second line contains ( n ) space-separated integers representing the temperatures for each day.
outputFormat
Output ( n ) space-separated integers on one line. The ( i)-th integer is the number of days you must wait after the ( i)-th day to get a warmer temperature. If there is no such day, output 0 for that day.## sample
4
73 74 75 71
1 1 0 0
</p>