Daily Temperatures
Problem
You are given an integer array temperatures where temperatures[i] is the forecast for day i. For every day, determine how many days you must wait until a strictly warmer day arrives. If no warmer day ever comes, the answer for that day is 0. Return the answers as an array answer of the same length.
- The forecast covers between 1 and 200,000 days.
- Each temperature is an integer between 20 and 110 inclusive.
Examples
temperatures = [64, 68, 66, 66, 71, 60, 59, 75]→[1, 3, 2, 1, 3, 2, 1, 0]. Day 1 (68) waits three days for day 4 (71); the two 66s each wait for day 4 as well, so the first of them waits 2 and the second waits 1; day 7 never sees a warmer day.temperatures = [55, 62, 70, 81]→[1, 1, 1, 0]. Strictly increasing: every day is answered by the next one.temperatures = [95, 80, 80, 45]→[0, 0, 0, 0]. Nothing warmer ever arrives, and the tie between the two 80s does not count as warmer.
Hints
- For each day, you are looking for the next day with a larger value. Which days can never be the answer for any earlier day once a warmer day has been seen?
- Keep the days whose answer is still unknown. What ordering do their temperatures have?
- Maintain a stack of indices with decreasing temperatures; when a warmer day arrives, pop every colder day and fill in its answer using the index difference.
Last reviewed 8 September 2026
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.