#K69677. Daily Temperatures

    ID: 33140 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. If there is no future day with a higher temperature, output 0 for that day.

You are required to implement an efficient algorithm with a time complexity of \(O(n)\), where \(n\) is the number of days. The typical approach uses a stack to maintain the indices of temperatures which have not yet found a warmer day.

Example:

Input:
8
73 74 75 71 69 72 76 73

Output: 1 1 4 2 1 1 0 0

</p>

inputFormat

The input is provided via standard input (stdin) in the following format:

  • The first line contains a single integer \(n\), representing the number of days.
  • The second line contains \(n\) space-separated integers representing the temperatures of each day.

outputFormat

Output a single line with \(n\) space-separated integers. The \(i\)-th integer indicates the number of days you must wait after day \(i\) to encounter a warmer temperature. If there is no such day, output 0.

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