VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 06: Stacks and queues

Lesson 6.7 of 10 in this module Unrolled Pro

Daily Temperatures

For each day, how many days until a warmer one. From scanning forward from every day (O(n²)), to using the small temperature range to remember the next day of each temperature (O(n · range)), to a monotonic stack of days still waiting (O(n)). Then unbounded values, where the range trick dies, a 'warmer by at least d' rule, where the stack dies and the range trick wins, steps until the loss improves and what that says about early-stopping patience, and the online span of a metric.

about 10 min 6 Python examples 2 quick checks

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.

text
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).


1. Step 1: Clarify

That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson

Unlock "Daily Temperatures"

The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.

Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied
View Plans & Unlock All Lessons

From ₹167/mo (~$2/mo) · Cancel anytime · Instant activation

100% Risk-Free: 14-day no-questions-asked money-back guarantee