Problem · Array
Daily Temperatures
Learn this problemProblem statement
Given an integer array temps, return an array answer of the same length. For each index i, answer[i] is the number of days until the first later day whose temperature is strictly greater than temps[i].
If no later day is warmer, set answer[i] = 0.
Function
dailyTemperatures(temps: int[]) → int[]Examples
Example 1
temps = [73,74,75,71,69,72,76,73]return = [1,1,4,2,1,1,0,0]For day 2 with temperature 75, the next warmer value is 76 four days later. The final two days have no later warmer value.
Example 2
temps = [30,40,50,60]return = [1,1,1,0]Each of the first three days is followed immediately by a warmer day.
Example 3
temps = [30,60,90]return = [1,1,0]The next day is warmer for the first two entries, while the last entry has no future day.
Constraints
1 <= temps.length <= 100000.-10^9 <= temps[i] <= 10^9.