Loading
Loading
A weather service publishes a list of daily temperatures. For each day, readers want to know how many days they must wait until it gets warmer than that day.
Return an array where position i holds the number of days to wait after day i for a strictly warmer temperature. If no later day is warmer, put 0.
temps = [30, 38, 36, 35, 37, 40]day 0 (30)day 1 is warmer → wait 1day 1 (38)next warmer is day 5 → wait 4day 2 (36)day 4 is warmer → wait 2day 5 (40)nothing warmer follows → 0[1, 4, 2, 1, 1, 0]Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n) time · O(n) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
Day 1 waits four days for day 5's 40 degrees.
Example 2
Temperatures only fall, so no day ever gets warmer.