Count the days until a warmer day
Your task
A weather app shows, next to each day of a forecast, how long you have to wait for warmer weather.
Write daily_temperatures(temps) that returns, for each day, how many days pass until a warmer day.
Input and output:
temps: a list of 1 to 100,000 daily temperatures, each an integer from 30 to 100.- Returns a list of integers, one per day, in the same order as
temps.
Rules:
- For day
i, find the first later dayjwhose temperature is strictly higher thantemps[i]. The answer for dayiisj - i. - A later day with the same temperature is not warmer.
- If no later day is warmer, the answer for that day is 0. The last day's answer is always 0.
Examples
daily_temperatures(temps: list[int]) -> list[int]Example 1
Input
daily_temperatures([73, 74, 75, 71, 69, 72, 76, 73])Output
[1, 1, 4, 2, 1, 1, 0, 0]Example 2
Input
daily_temperatures([80, 70, 70, 90])Output
[3, 2, 1, 0]