44. Daily Temperatures
For each day, find the first later day with a higher temperature and report how many days away it is. Report zero if no later day is warmer.
An equal temperature is not warmer. The result is a distance in days, rather than the warmer temperature or its absolute index.
Example 1
Input
[73,74,75,71,69,72,76,73]
Output
[1,1,4,2,1,1,0,0]
Explanation: Day 2 waits until day 6, while days 6 and 7 have no warmer future day.
Example 2
Input
[70,70,71]
Output
[2,1,0]
Explanation: Equal temperatures remain unresolved until 71 arrives.
Constraints
0 <= temperatures.length <= 105-231 <= temperatures[i] <= 231 - 1
Hints
Hint 1
Keep earlier positions whose answer is still unknown.
Hint 2
Which unresolved positions can today answer?
Hint 3
Pop every cooler top, assign its distance, then push today.
Submissions
Your recent submissions for this problem.
Checking sign-in…
Discussion
Ask a question or share an approach. Posts are public; avoid personal information and mark solution spoilers clearly.
No discussion yet. Start the conversation with a question about this problem.
Checking sign-in…
Run your code to check the sample cases, or submit it to check the full validation suite.
One day resolves several
[3,2,1,4]
[3,2,1,0]