CodeSpeek

Daily Temperatures

Medium · Stack

You are given a list of daily temperatures. For each day, determine how many days you would need to wait until a strictly warmer temperature occurs; if no such future day exists, use 0 for that day. Return a list of these wait counts, one per input day, in the same order.

Examples

Input:  temperatures = [73,74,75,71,69,72,76,73]
Output: [1,1,4,2,1,1,0,0]
Why:    For each day, count how many days until a strictly warmer day appears; the last two days never get warmer so they are 0.
Input:  temperatures = [30,40,50,60]
Output: [1,1,1,0]
Why:    Each day is followed immediately by a warmer one except the last.
Input:  temperatures = [30,30,30]
Output: [0,0,0]
Why:    No day ever gets strictly warmer than a previous one since all values tie.

Constraints

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

Practise it by voice

Describe the solution out loud and the interviewer writes exactly what you say, asks when you are vague, and runs the tests in your browser.

Practise Daily Temperatures

This statement is written for CodeSpeek. The problem is part of the NeetCode 150 list; Watch NeetCode's explanation of Daily Temperatures. Reference solutions from the NeetCode repository (MIT) are used to verify our tests.