FAANG · LeetCode #739
Daily Temperatures — three-stage drill
1The ProblemMedium
Daily Temperatures
For each day, how many days until a warmer temperature.
Examples
[73,74,75,71,76]→ [1,1,2,1,0]
constraint0 if no warmer day follows.
2The PatternTIME O(n) · SPACE O(n)
Monotonic Stack
A stack kept sorted; each new value pops everything it resolves, so each element is pushed and popped once — O(n).
Problems using this pattern
3The SolutionRESULT → [1,1,2,1,0]
Step through it
stack holds indices of days still waiting — kept in decreasing temperature
Step 1 / 11
Arrow keys to navigate · escape to reset