#C14606. Daily Temperatures
Daily Temperatures
Daily Temperatures
You are given a sequence of daily temperatures. For each day, your task is to determine how many days you would have to wait until a warmer temperature occurs. If there is no future day for which this is possible, output 0 for that day.
This problem can be mathematically expressed as follows: for an array \(T\) of temperatures, for each index \(i\) find the smallest index \(j\) (with \(j > i\)) such that \(T[j] > T[i]\). The answer for index \(i\) is \(j - i\) if such a \(j\) exists; otherwise, the answer is 0, i.e. \(\mathit{answer}[i]=0\).
Input: The input starts with a single integer \(n\) representing the number of days, followed by a line of \(n\) integers representing the daily temperatures.
Output: Output \(n\) integers separated by spaces. The \(i\)-th integer represents the number of days until a warmer temperature for that day.
inputFormat
The input is read from standard input (stdin). The first line contains an integer (n) (1 ≤ n ≤ 10^5) which denotes the number of days. The second line contains (n) space-separated integers representing the daily temperatures.
outputFormat
The result is written to standard output (stdout) as (n) space-separated integers. The (i)-th integer is the number of days you must wait until a warmer temperature. If no such day exists, output 0 for that position.## sample
8
73 74 75 71 69 72 76 73
1 1 4 2 1 1 0 0