Gamified challenge · Monotonic stack
temps[i] is the temperature on day i. For every day, find how many days you have to wait for a strictly warmer day. If no warmer day ever comes, the answer for that day is 0.
Write daysToWarmer(temps) (Python: days_to_warmer(temps)) that returns a list of the same length, in day order.
Example: [73, 74, 75, 71, 69, 72, 76, 73] gives [1, 1, 4, 2, 1, 1, 0, 0]. Day 2 (75°) waits 4 days for 76°; an equal temperature doesn't count as warmer.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google