All problems
Daily Temperatures
Problem
For each day, return how many days must pass until a warmer temperature.
temps holds the daily temperatures. Use a monotonic stack of indices with decreasing temperatures; a warmer day resolves every colder day waiting on the stack.
Return a list where result[i] is the wait in days, or 0 when no warmer day exists later.
Hint
Keep unresolved days on the stack until a warmer temperature arrives.
Test cases
case 1
in: [[73,74,75,71,69,72,76,73]]
expected: [1,1,4,2,1,1,0,0]
case 2
in: [[30,40,50,60]]
expected: [1,1,1,0]
case 3
in: [[30,30,30]]
expected: [0,0,0]
case 4
in: [[90,80,70]]
expected: [0,0,0]
case 5
in: [[]]
expected: []
Starter codePython
def daily_temperatures(temps):
# Your code here
pass5 test cases · run your code against them in the editor