739. Daily Temperatures - LeetCode
class Solution:
def dailyTemperatures(self, temperatures: list[int]) -> list[int]:
result = [0] * len(temperatures)
stack = []
for r in range(len(temperatures)):
while stack and temperatures[stack[-1]] < temperatures[r]: # l < r
l = stack.pop()
result[l] = r - l
stack.append(r)
return result