Skip to content
BASA DSA

Daily Temperatures

MediumStack

For each temperature, return how many days until a strictly warmer day; return zero if none follows.

Example 1

Input
temperatures = [60,60,61,59,70]
Output
[2,1,2,1,0]

Explanation

Equal 60 is not warmer: the first day waits two days for 61, and 59 waits one for 70.

Example 2

Input
temperatures = [90,80,70]
Output
[0,0,0]

Explanation

Every later day is colder, so all waits are zero.

Example 3

Input
temperatures = [40]
Output
[0]

Explanation

The single temperature has no later day.

Constraints

  • 1 <= number of temperatures <= 100000
  • Temperatures are 30..100

Function contractdailyTemperaturesArguments: json
Loading draft…
SolutionRuns on your device
Loading draft…