Problems › Stacks & queues

Daily Temperatures

Difficulty: Medium · Topic: Stacks & queues

Given a list of daily temperatures, return a list where answer[i] is the number of days to wait until a warmer temperature. If there is no future warmer day, put 0.

Examples

daily_temperatures([73,74,75,71,69,72,76,73])
→ [1,1,4,2,1,1,0,0]
daily_temperatures([30,40,50,60])
→ [1,1,1,0]

Target complexity: time O(n), space O(n)

Write your solution in Python and run it against hidden tests right on this page. Progressive hints and Python + C++ reference solutions are included.

Learn the idea first: the lesson for this problem.

More Stacks & queues problems