Back to problems Solve on LeetCode →

Daily Temperatures

LeetCode 739 • Medium • Stack

Given an array of daily temperatures, return an array where answer[i] is the number of days until a warmer temperature. Use a monotonic decreasing stack of indices.

TimeO(n)each index pushed/popped once
SpaceO(n)stack
Index: Stack: []
Current
In Stack
Answered
Default
answer[]
Stack
[]
Ready
Press Play. Scan left to right: pop stack while current temp > top, push current index. Monotonic decreasing stack.