Skip to main content
LeetCode 739, Medium. Topics: Array, Stack, Monotonic Stack. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 35 parametrized pytest cases, and a playground notebook:

Problem

Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead.

Examples

Explanation:
  • For input [73,74,75,71,69,72,76,73], the output should be [1,1,4,2,1,1,0,0].
  • For example, the first temperature is 73. The next warmer temperature is 74, which is 1 day later, so we put 1.
  • The second temperature is 74. The next warmer temperature is 75, which is 1 day later, so we put 1.
  • The third temperature is 75. The next warmer temperature is 76, which is 4 days later, so we put 4.

Constraints

  • 1 <= temperatures.length <= 10^5
  • 30 <= temperatures[i] <= 100

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Grind, NeetCode 150, NeetCode 250, NeetCode All.
Last modified on August 25, 2026