Monotonic stack: Daily Temperatures

A monotonic stack keeps its items in sorted order. Before you push, you pop everything the new item "beats". Each item is pushed once and popped at most once, so the whole pass is O(n).

The signal: "the next greater" or "the previous smaller" element for every position.

For daily temperatures, keep a stack of day indices still waiting for a warmer day. Their temperatures go down from bottom to top. When today is warmer than the day on top, that day has found its answer: today - day. Pop it and check the next one.

A common mistake: storing temperatures instead of indices. You need the index to compute the distance.

The brute force looks ahead from every day. With temperatures that only go down, it is O(n²).

Exercise: finish days_until_warmer. For each day, return how many days until a warmer temperature, or 0 if none comes. Press Check to run the tests.