#K93627. Daily Temperatures

    ID: 38462 Type: Default 1000ms 256MiB

Daily Temperatures

Daily Temperatures

You are given an array of integers representing the daily temperatures. For each day, 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.

The solution should be efficient, ideally running in O(n) time complexity using a stack-based approach.

Mathematical Formulation:

For an array \(T\) of length \(n\), compute an array \(A\) such that for each index \(i\):

\[ A_i = \begin{cases} i' - i, & \text{if } T[i'] > T[i] \text{ and } i' \text{ is the smallest such index};\\ 0, & \text{if no such } i' \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 temperatures for each day.

outputFormat

Output a single line with \(n\) space-separated integers, where the \(i\)-th integer is the number of days you have to wait after the \(i\)-th day to get a warmer temperature. If there is no such day, output 0 for that position.

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