Dsa
Monotonic Stack
Hard
Temperature Peaks
You are tracking daily temperatures for a city. You want to find out the number of days until the next warmer temperature for each day. If there is no warmer future day, output 0 for that day.
Input Format:
- The first line contains an integer n (1 <= n <= 10^5), the number of days.
- The second line contains n space-separated integers, each representing the temperature for a day.
Output Format:
- Output a single line containing n space-separated integers, where the ith integer is the number of days until the next warmer temperature.
Example:
Input:
5
73 74 75 71 69
Output:
1 1 0 0 0
Key concepts
monotonic_stacktemperaturearrays
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now