Problem. Given daily temperatures temps, return wait where wait[i] is the number of days after day i until
a strictly warmer day, or 0 if there is none.
temps = [73, 74, 75, 71, 69, 72, 76, 73] → [1, 1, 4, 2, 1, 1, 0, 0]
temps = [30, 60, 90] → [1, 1, 0]
It's the next greater element (lesson 6.4) asked as a distance, so the stack stores indices. This lesson is about something else too: a second, "worse" optimisation that becomes the right one when the constraints change.
ML context. Replace temperature with validation loss and "warmer" with "lower": wait[i] is how many steps
passed before training improved on step i. The longest such wait is the patience an early-stopping rule needed to
avoid quitting too soon (Change C). The mirror question, "how long has this metric been at or below today's level",
is the span of a GPU utilisation or latency series (Change D).