609. Daily Temperatures

MediumStackMonotonic StackStack

Given a list of daily temperatures, return an array where each entry is the number of days you must wait for a warmer temperature, or 0 if none comes. The input is JSON {temperatures}.

Input: JSON {temperatures}.

Output: Array — days to wait for each day.

Examples

Example 1
Input: {"temperatures":[73,74,75,71,69,72,76,73]}
Output: [1,1,4,2,1,1,0,0]
Explanation: Days until a warmer temperature.
Example 2
Input: {"temperatures":[30]}
Output: [0]
Explanation: No warmer day.
Example 3
Input: {"temperatures":[90,80,70]}
Output: [0,0,0]
Explanation: Only cooling.

Constraints

Asked by

SwiggyAmazonBloombergMicrosoftGoogleMeta
Solve this problem in the editor →