Dsa
Monotonic Stack
Easy
Temperature Trend Tracking
You are given the daily temperatures for a week. For each day's temperature, determine how many days until the temperature will be higher than the current day's temperature. If there is no future day with a warmer temperature, return 0. Your program should read the number of days and then the temperatures, and for each day, print the number of days until a warmer day.
Input format:
The first line contains a single integer, n (1 <= n <= 100), the number of days.
The second line contains n integers representing the daily temperatures, where each temperature is between -100 and 100.
Output format:
Print n integers as space-separated values, where each integer is the number of days until a warmer day, or 0 if there is no such day.
Example:
Input:
7
73 74 75 71 69 72 76
Output:
1 1 4 2 1 1 0
Key concepts
monotonic_stackarraytemperature
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