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

Lesson 6.9 of 10 in this module Unrolled Pro

Sliding Window Maximum

The maximum of every window of k consecutive values. From taking max() of each window (O(n·k)), to a heap with lazy deletion (O(n log n)), to a monotonic deque that drops dominated values from the back and expired ones from the front (O(n)). Then the window minimum and both at once, windows defined by time instead of count, a block trick with prefix and suffix maxima that has no data-dependent loop, and a sparse table for arbitrary range-maximum queries.

about 10 min 5 Python examples 2 quick checks

Problem. Given nums and a window size k, return the maximum of each window nums[i : i + k] as the window slides from left to right.

text
nums = [1, 3, -1, -3, 5, 3, 6, 7], k = 3   →   [3, 3, 5, 5, 6, 7]
nums = [9, 8, 7], k = 1                     →   [9, 8, 7]

Module 04 slid windows with a running sum: adding the new value and subtracting the old one. The maximum can't be "subtracted": when the current maximum leaves the window, what's the next largest? Keeping that answer ready is the job of a monotonic deque.

ML context. Rolling maxima are everywhere in monitoring and signal processing: peak GPU memory over the last minute (lesson 6.10), the worst latency in a window, max-pooling in a 1D convolutional network (window k with stride 1), and the upper envelope of a noisy loss curve.


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 "Sliding Window Maximum"

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