#C7971. Daily Warmer Temperatures

    ID: 51901 Type: Default 1000ms 256MiB

Daily Warmer Temperatures

Daily Warmer Temperatures

Given an array of integers representing the daily temperatures, compute an array where each element is the number of days you have to wait until a warmer temperature occurs. Formally, let \(T_i\) be the temperature on day \(i\) (0-indexed), then the output for that day is defined as:

[ \text{result}[i]=\begin{cases} \min{j-i, :, j>i \text{ and } T_j>T_i} & \text{if such } j \text{ exists}\ 0 & \text{otherwise} \end{cases} ]

If no warmer day exists in the future, output 0 for that day. This problem requires an efficient solution ideally using a stack to keep track of indices.

inputFormat

The input is given via standard input (stdin):

  • The first line contains an integer \(n\) (where \(1 \le n \le 10^5\)), representing the number of days.
  • The second line contains \(n\) space-separated integers representing the temperatures.

outputFormat

Output a single line to standard output (stdout) containing \(n\) space-separated integers. The \(i\)-th integer represents the number of days you must wait for a warmer temperature. If no such day exists, output 0 for that day.

## sample
8
73 74 75 71 69 72 76 73
1 1 4 2 1 1 0 0