Skip to main content
Back to problems
Leetcode
Medium
Arrays
Stacks
Amazon
Google
Daily Temperatures

Given a list of daily temperatures, return how many days you must wait for a warmer temperature for each day.

Acceptance 100%
Problem Statement

Daily Temperatures

You are given an array of integers temperatures, where temperatures[i] is the temperature on day i.

For each day, find out how many days you would have to wait until a warmer temperature appears. If there is no future day with a warmer temperature, the answer for that day is 0.

Return an array answer such that answer[i] is the number of days after day i until a warmer temperature occurs.

The task is to process the array efficiently, especially when the number of days is large.

Input Format

  • A single integer array temperatures.
  • temperatures[i] represents the temperature on day i.

Output Format

  • Return an integer array answer of the same length.
  • answer[i] is the number of days to wait for a strictly warmer temperature after day i, or 0 if none exists.

Constraints

  • 1 <= temperatures.length
  • Each temperatures[i] is an integer.
  • The required result should be computed efficiently in linear time.
Examples
Sample cases returned by the problem API.

Example 1

Input

temperatures = [73,74,75,71,69,72,76,73]

Output

[1,1,4,2,1,1,0,0]

Explanation

  • Day 0 waits 1 day for 74.
  • Day 1 waits 1 day for 75.
  • Day 2 waits 4 days for 76.
  • Day 3 waits 2 days for 72.
  • Day 4 waits 1 day for 72.
  • Day 5 waits 1 day for 76.
  • Days 6 and 7 have no warmer future day.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.