WRITE · TRACE · UNDERSTAND

Monotonic Stack

Resolve waiting days as a warmer temperature arrives

Your experiment

warmer_days(temperatures) gives the number of days until a strictly warmer day, or zero. Use pending indices to avoid restarting a search for every day.

Python runs in your browser. Your draft stays on this device.

What to look for

The pending stack stores indices whose warmer day has not arrived. Each index enters and leaves once. Equal temperatures stay pending because the question asks for a strictly warmer day.

Watch your code work

Ready to experiment

Write a solution or load the worked answer, then choose Trace & check.

Step through arrays, variables and training curves produced by your own Python.