- Daily Temperatures
Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead.
var dailyTemperatures = function(temperatures) {
const stack = []
for (let i = 0; i < temperatures.length; i++) {
while (stack.length > 0 && temperatures[i] > stack[stack.length - 1][0]) {
const [temp, index] = stack.pop()
temperatures[index] = i - index
}
stack.push([temperatures[i], i])
}
while (stack.length > 0) {
const [temp, index] = stack.pop()
temperatures[index] = 0
}
return temperatures
}