Daily Temperatures
01 · Problem
Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead.
02 · Examples
temperatures = [73,74,75,71,69,72,76,73]
[1,1,4,2,1,1,0,0]
For day 0 (73°), the next warmer day is day 1 (74°). For day 2 (75°), the next warmer day is day 6 (76°). The last two days have no warmer future day.
temperatures = [30,40,50,60]
[1,1,1,0]
Each day's next warmer temperature is the very next day, except the last day which has no warmer future day.
temperatures = [30,60,90]
[1,1,0]
Day 0 waits 1 day for 60°, day 1 waits 1 day for 90°, and day 2 has no warmer day ahead.
03 · Constraints
- 011 <= temperatures.length <= 105
- 0230 <= temperatures[i] <= 100
04 · Optimal complexity
- Time
- O(n)
- Space
- O(n)
Practice it alone or rehearse it as an interview.
Practice Mode gives you an editor and test runs, nothing else. AI Interview Mode puts a voice interviewer on the other side, adds a clock, and ends with a scored summary of the round.