Next Warmer Day

MediumStack≈ 30 min

You are given a list temps of daily temperatures. For each day, find how many days you would have to wait for a strictly warmer day. If no warmer day follows, the answer for that day is 0.

Return the answers as a list, one per day.

Examples

text
temps = [20, 22, 21, 19, 25, 18]  →  [1, 3, 2, 1, 0, 0]
temps = [10, 11, 12]              →  [1, 1, 0]
temps = [40, 30, 50]              →  [2, 1, 0]

On day 1 it is 22; the next warmer day is day 4, at 25, three days later.

Constraints

  • Between 1 and 100,000 days, each between −100 and 100 degrees.
  • Aim for O(n): each day should enter and leave your bookkeeping once.
Sound off. Turn on for key clicks and a chime when the tests pass.Inline suggestions off. Recommended while you are learning. Turn on to complete words as you type.
Console
›Run to see what your code prints

Run checks the 3 visible cases here, in your browser. Submit runs all 6 on the judge, 3 of them hidden, and measures how your solution scales.