You are given an array `temperatures` where `temperatures[i]` is the temperature recorded on day `i`.
For each day, determine how many days you must wait until a warmer temperature occurs. If no future day is warmer, the answer for that day is `0`.
Return an array `answer` such that `answer[i]` is the number of days to wait after day `i` for a warmer temperature.
Example 1
Input: temperatures = [73,74,75,71,69,72,76,73]
Output: [1,1,4,2,1,1,0,0]
Day 0 (73) warms up the next day (74), so 1. Day 2 (75) waits 4 days for 76. The last two days never see anything warmer, so 0.
Example 2
Input: temperatures = [30,40,50,60]
Output: [1,1,1,0]
Each day is immediately followed by a warmer one except the final day, which has no warmer future day.
Constraints
1 <= temperatures.length <= 10^530 <= temperatures[i] <= 100See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.
FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.
750+ engineers trained · frontend, backend, AWS & AI