Skip to main content

Daily Temperatures

MediumPremium

Given an array of integers temperatures that denotes daily temperatures, return an array result where result[i] represents the number of days after the i-th day until a day with a higher temperature occurs. If no future day has a higher temperature, set result[i] to 0.

Examples

Input: temperatures = [50,60,72] Output: [1,1,0]
  • For day 0 (50°F), the next warmer day is day 1 (60°F), so result[0] = 1.
  • For day 1 (60°F), the next warmer day is day 2 (72°F), so result[1] = 1.
  • For day 2 (72°F), there is no warmer day, so result[2] = 0.