Monotonic decreasing stack of indices. Pop when warmer day found.
function dailyTemperatures(temperatures): n = len(temperatures) answer = [0] * n stack = [] for i in range(n): while stack and temperatures[i] > temperatures[stack[-1]]: prevDay = stack.pop() answer[prevDay] = i - prevDay stack.push(i) return answer
time, space.