Daily Temperatures
You get the temperature of each day in a row. For every day, say how many days you have to wait for a strictly warmer one; if no warmer day ever comes, the answer is 0. Our example: [64, 61, 61, 59, 66, 62, 63] gives [4, 3, 2, 1, 0, 1, 0].
- input
temperatures: the temperature of each day, in order.- returns
- For every day, how many days later a strictly warmer day comes, or
0if none ever does. - constraints
- 1 ≤ temperatures.length ≤ 10⁴
- 30 ≤ temperatures[i] ≤ 100
- examples
- Open a test in the tests panel: it shows the input and the expected answer.
/**
* @param {number[]} temperatures
* @return {number[]}
*/
function dailyTemperatures(temperatures) {
}
Ctrl ↵
format
reset
saved in this browser
Stuck?
See the solution run step by step on our example, then why it works and its complexity.
Next: more monotonic stack problems
The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.