Skip to content
RED SAGSkills
medium30 ptsstacksarrays

Days Until Warmer

temps[i] is the temperature on day i. For each day, return how many days you must wait until a strictly warmer day. If no warmer day follows, use 0.

Example 1

Input: temps = [73, 74, 75, 71, 69, 72, 76, 73]
Output: [1, 1, 4, 2, 1, 1, 0, 0]

Example 2

Input: temps = [30, 30, 30]
Output: [0, 0, 0]

Constraints

  • 1 <= temps.length <= 10^5
  • -50 <= temps[i] <= 60
Hint 1

Keep a stack of days that are still waiting for a warmer day.

Hint 2

When today is warmer than the day on top of the stack, that day has its answer.

Good practice for: Frontend Developer, Backend Developer, Full Stack Developer, Mobile App Developer, Game Developer, Automation Test Engineer, Data Scientist

Run checks your code on 2 sample tests. Submit runs all 7 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.