VISUALGO//PROBLEMS
daily temperatures · monotonic stackmedium
LeetCode #739
day
·
wait
·
temperatures
·
·
·
·
·
·
·
·
stack
·
·
·
answer
·
·
·
·
·
·
·
·
ELEMENTS
temperatures
Python
def dailyTemperatures(temperatures: list[int]) -> list[int]:
    answer = [0] * len(temperatures)
    stack = []  # days still waiting, temperatures falling
    for today, temp in enumerate(temperatures):
        while stack and temp > temperatures[stack[-1]]:
            day = stack.pop()
            answer[day] = today - day
        stack.append(today)
    return answer