VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 04: Sliding window

Lesson 4.1 of 10 in this module Unrolled Pro

Fixed and Variable Windows

Why most 'best contiguous range' questions are O(n): a window that slides keeps its summary up to date by adding what enters and removing what leaves. The fixed-size template, the expand-and-shrink template for variable windows, the condition that makes shrinking safe (monotone validity), what breaks it (negative numbers), and the 'exactly k = at most k minus at most k − 1' counting trick.

about 10 min 4 Python examples 1 quick checks

The question this module answers: what's the best contiguous range? There are n(n + 1)/2 contiguous ranges in an array of n values. Checking each one from scratch is O(n²) or O(n³). A sliding window visits them in an order where each range differs from the last by one element entering or leaving, so its summary (a sum, a count, a set) updates in O(1). Every element enters once and leaves once: O(n).

ML context. Windows are everywhere in ML code:

  • Rolling averages of training loss, latency or a production metric.
  • n-grams: every run of n consecutive tokens.
  • Time-series features: counts and sums over the last hour, the last 1,000 events.
  • Context windows: which tokens a model can see, and chunking long documents with overlap.

1. The problem: recomputing every range

Task: the largest sum of any 3 consecutive values.

Neighbouring windows share k − 1 values, yet each sum starts from zero: O(n·k).

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

Unlock "Fixed and Variable Windows"

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