Dsa
Monotonic Stack
Medium
Temperature Variance
You are given a list of daily temperatures measured in degrees. Your task is to calculate the variance of temperatures, which is defined as the difference between the maximum and minimum temperature recorded over the next days until a warmer temperature is found. If there is no warmer temperature in the future, record it as zero. Write a function that reads a list of temperatures and outputs the variance for each day.
Input format:
- The first line contains an integer n (1 <= n <= 100000), the number of days.
- The second line contains n space-separated integers representing daily temperatures.
Output format:
- Print a single line containing n space-separated integers representing the temperature variance for each day.
Example:
Input:
5
30 40 50 30 60
Output:
0 10 20 0 0
Key concepts
monotonic_stackarraystemperature
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