#K83152. Daily Temperatures
Daily Temperatures
Daily Temperatures
Given a list of daily temperatures, for each day, determine the number of days you must wait until a warmer temperature occurs. If there is no future day for which this is possible, output 0 for that day.
For example, if the input is a sequence of temperatures T = [73, 74, 75, 71, 69, 72, 76, 73], then the output should be [1, 1, 4, 2, 1, 1, 0, 0].
Note: The solution is required to read input from standard input (stdin) and write output to standard output (stdout).
Mathematically, if T is the list of temperatures and ans[i] is the answer for day i, then:
[
ans[i] = \begin{cases}
j - i, & \text{if } j \text{ is the smallest index such that } T[j] > T[i],\
0, & \text{if no such } j \text{ exists.}
\end{cases}
]
inputFormat
The first line of input contains an integer n, the number of days. The second line contains n space-separated integers representing the daily temperatures.
outputFormat
Output a single line of n space-separated integers, where the i-th integer is the number of days you must wait until a warmer temperature. If there is no future day with a higher temperature, output 0 for that position.## sample
8
73 74 75 71 69 72 76 73
1 1 4 2 1 1 0 0