Daily Temperatures
Medium Stack & Queue AI round
temperatures[i] is the temperature on day i, in tenths of a degree: 215 is 21.5 degrees.
For each day, look ahead for the first later day that is warmer: one with a higher temperature. The day's wait is how many days later that warmer day comes.
Return a list of the wait for every day, in order, with 0 for a day that no later day is warmer than.
Example 1
Day 0 is 21.5 degrees, and the first warmer day is day 3, at 24.0: three days later. Days 4 and 5 are both 18.7, and a day of the same temperature is not warmer, so day 4 waits for day 6, two days later.
Example 2
Equal days are not warmer, so no day gets a warmer one.
Example 3
Constraints
1 ≤ temperatures.length ≤ 5 × 10⁵-500 ≤ temperatures[i] ≤ 500
Practice this in an AI round
30 minutes on this problem with an AI agent beside your code, then a report on your solution and how you used the agent.
Your first AI round is free.
Watch the explanation
More Stack & Queue
- Valid ParenthesesAI round · Easy
- Decode StringAI round · Medium
- Largest Rectangle in HistogramHard
- Maximal RectangleHard
- Remove K DigitsMedium