Daily Temperatures
Given a daily temperatures array, return an array answer where answer[i] is the number of days you have to wait after day i to get a warmer temperature. If no future day is warmer, answer[i] is 0.
Open official problem prompt ↗For every day, measure the distance to the first later day that is strictly warmer, in a single pass instead of comparing every pair.
Imagine people standing in a line each holding a thermometer, waiting for someone taller behind them. Each person waits until a taller person walks up; the moment that happens they leave the queue and note how long they waited.
- Input
- temperatures = [73, 74, 75, 71, 69, 72, 76, 73]
- Output
- [1, 1, 4, 2, 1, 1, 0, 0]
- Why
- Day 0 (73) sees 74 the next day (wait 1); day 2 (75) must wait until day 6 (76), which is 4 days.
1 <= temperatures.length <= 10^530 <= temperatures[i] <= 100