Pattern Recognition Drill
Medium Stacks & Queues
The Problem
Given daily temperatures, for each day find how many days until a warmer temperature.
What approach would you use?
Think about it before scrolling down.
Decreasing stack of indices. Pop while current temp > stack top. Distance = current - popped index. O(n).
Same approach. Each element pushed and popped at most once.
Common Trap
Don't scan forward from each day — that's O(n²). The monotonic stack makes it one pass.