AlgoLounge

Daily Temperatures

medium

Leetcode 739. Daily Temperatures

You are given an array of integers temperatures where temperatures[i] represents the daily temperatures on the ith day.

Return an array result where result[i] is the number of days after the ith day before a warmer temperature appears on a future day. If there is no day in the future where a warmer temperature will appear for the ith day, set result[i] to 0 instead.

Examples

Example 1

Input:  temperatures = [30,38,30,36,35,40,28]
Output: [1,4,1,2,1,0,0]

Example 2

Input:  temperatures = [22,21,20]
Output: [0,0,0]

Constraints

  • 1 <= temperatures.length <= 1000
  • 1 <= temperatures[i] <= 100
TypeScript
Loading editor…
List of test cases (11)
Case 1
temperatures = [30,38,30,36,35,40,28]
Case 2
temperatures = [22,21,20]
Case 3
temperatures = [89,62,70,58,47,47,46,76,100,70]
Case 4
temperatures = [73,74,75,71,69,72,76,73]
Case 5
temperatures = [55]
Case 6
temperatures = [30,40,50,60]
Case 7
temperatures = [60,50,40,30]
Case 8
temperatures = [75,71,76,73,68,72,77]
Case 9
temperatures = [90,80,70,85,95]
Case 10
temperatures = [34,80,80,34,34,80,80,80,80,34]
Case 11
temperatures = [50,50,50,60]