Daily Temperatures
Given an array of daily temperatures, return an array where each element tells you how many days you have to wait until a warmer temperature. If no future day is warmer, put 0.
Output as space-separated integers.
Example
73,74,75,71,69,72,76,73
1 1 4 2 1 1 0 0
- We start by iterating over the input array from left to right, comparing each temperature with the subsequent ones to find a warmer temperature.
- For the first element , we find a warmer temperature on the next day, so the output is .
- We repeat this process for each element: is followed by , which is warmer, so the output is ; is followed by temperatures that are not warmer until , which is days later, so the output is .
- The rest of the elements are processed similarly, resulting in the output array:
Constraints
- 1 <= len(temperatures) <= 10^5
- 30 <= temperatures[i] <= 100