Back to Practice
#0096

Daily Temperatures

MediumDSA25 min20 XP

Problem

Given temperatures, return how many days each position must wait for a warmer temperature. Use 0 if none exists.

Why This Matters

Next-greater-element problems show why stacks can remember unresolved positions efficiently.

Function Signature

def daily_temperatures(temperatures):

Examples

Example 1
Input[73,74,75,71,69,72,76,73]
Output[1,1,4,2,1,1,0,0]

Each index waits until the next warmer temperature appears.

Constraints

  • Return the exact structure requested.
  • Handle the edge cases mentioned in the prompt.
  • Prefer clear logic over clever one-liners.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Input[73,74,75,71,69,72,76,73]
Expected[1,1,4,2,1,1,0,0]

Each index waits until the next warmer temperature appears.

Hidden Test Categories
strictly decreasingstrictly increasingequal temperatures