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

Lesson 4.2 of 10 in this module Unrolled Pro

Maximum Sum Subarray of Size K

The largest sum of k consecutive values. From summing every window (O(n·k)), to prefix sums (O(n) time, O(n) space), to a sliding sum (O(n) time, O(1) space). Then windows of at least or at most k, a stream that never ends, floating-point drift in long-running sums, and 2D windows.

about 10 min 4 Python examples 2 quick checks

Problem. Return the maximum sum of any k consecutive values in nums.

text
nums = [2, 1, 5, 1, 3, 2], k = 3   →   9      (5 + 1 + 3)
nums = [2, 3, 4, 1, 5],    k = 2   →   7      (3 + 4)

ML context. "The best (or worst) k-step stretch" is a windowed aggregate: the worst 5-minute error rate in a day of logs, the highest 1,000-request latency sum, the 10 epochs with the biggest total improvement. The sliding sum is also the engine of every rolling average in a training dashboard (lesson 4.9).


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 "Maximum Sum Subarray of Size K"

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