Daily Temperatures

Medium · Monotonic Stack · Array · Stack · Monotonic Stack

Problem

Given a list of daily temperatures, return an array where position i holds the number of days you must wait after day i for a warmer temperature. If no warmer day ever comes, put 0.

Examples

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

Day 2 (75) waits four days for 76; the last two never warm up.

Input: temperatures = [30,40,50,60]
Output: [1,1,1,0]

Each day is followed immediately by a warmer one.

Constraints

Approaches

Related problems

Start free on Cariara · Coding problems · System design studio

Starting Python
No results yet.

          
↑↓ move ↵ open esc close

Labs

Loading labs…

Run with your own input

Starting Python

Loading Python…