38. Daily Temperatures

Given an array temperatures, where temperatures[i] is the temperature on day i. Return an array answer, where answer[i] is the number of days until a warmer temperature after day i. If there is no such day, answer[i] = 0.
Example 1
Input: temperatures = [73,74,75,71,69,72,76,73]
Output: [1,1,4,2,1,1,0,0]
Explanation: For 73, the nearest warmer day is 1 day away; for 75, it is 4 days away; for 76 and the last 73, there is no warmer day.
Example 2
Input: temperatures = [30,60,90]
Output: [1,1,0]
Explanation: Each following day is warmer than the previous one; the last day has no answer.
Example 3
Input: temperatures = [30,40,50,60]
Output: [1,1,1,0]
Explanation: The temperature rises each day, so the wait is 1 everywhere except on the last day.
arraysmediumstack
JavaScript
Loading...
Line 1, Char 1