Daily Temperatures
Problem Statement
You get the daily temperatures as an array temperatures, one value per day.
For each day, find out how many days you have to wait until a strictly warmer day comes. If no warmer day ever comes, the answer for that day is 0.
An integer array temperatures.
An array answer of the same length, where answer[i] is the number of days after day i until a warmer temperature, or 0.
Day 2 (75°) waits until day 6 (76°): 4 days. Day 3 (71°) waits until day 5 (72°): 2 days. Days 6 and 7 never see a warmer day.
Every day is followed directly by a warmer one, except the last.
- • 1 ≤ temperatures.length ≤ 10^5
- • 30 ≤ temperatures[i] ≤ 100
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
For each day, walk forward until a strictly warmer day
One pass; a warmer day pops every cooler waiting day and writes its distance
For each day i, look at days i+1, i+2, … until one is strictly warmer. The answer is the distance j − i. If you reach the end, it stays 0.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like Monotonic Stack translate into production architectures and low-level memory mechanics.