Loading practice problems…
Loading your practice workspace…
Loading code editor…
26 / 29
Sign in
Algorithms/Stack

Daily Temperatures

medium30 min

Given daily temperatures, return an array where each position contains the number of days until a warmer temperature.

Use 0 when no warmer future day exists.

Example 1

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

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

Example 2

Inputtemperatures = [30, 40, 50, 60]

Output[1, 1, 1, 0]

Constraints

  • 1 ≤ temperatures.length ≤ 100,000
  • 30 ≤ temperatures[i] ≤ 100
StackMonotonic Stack