#C6234. Daily Temperatures

    ID: 49972 Type: Default 1000ms 256MiB

Daily Temperatures

Daily Temperatures

Given a list of daily temperatures, your task is to determine for each day how many days you would have to wait until a warmer temperature occurs. If there is no future day with a higher temperature, output 0 for that day.

The problem can be formally described as follows:

Given an integer array \(T\) of length \(n\), output an integer array \(R\) where for each index \(i\) (\(0 \leq i T[i]\); if no such \(R[i]\) exists, then \(R[i] = 0\).

This problem can be solved using a monotonic stack for efficient computation.

inputFormat

The first line of input contains a single integer \(n\) specifying the number of days.

The second line contains \(n\) space-separated integers representing the temperatures for each day.

outputFormat

Output a single line containing \(n\) space-separated integers, where the \(i\)-th integer is the number of days you have to wait after day \(i\) 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