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

Lesson 4.7 of 10 in this module Unrolled Pro

Fruit Into Baskets

The longest stretch of trees you can pick with two baskets, each holding one fruit type: the longest subarray with at most two distinct values. From every start (O(n²)), to a window with a count map, to an O(1)-memory version that remembers only the last two types and the length of the final run. Then k baskets, returning the stretch, and the longest period served by at most k model versions.

about 10 min 4 Python examples 2 quick checks

Problem. fruits[i] is the type of fruit on tree i. You have two baskets; each holds any amount of one type. Start at any tree and pick one fruit from every tree moving right, stopping when a fruit fits neither basket. Return the maximum number of fruits you can pick.

Stripped of the story: the length of the longest subarray with at most 2 distinct values.

text
[1, 2, 1]             →   3
[0, 1, 2, 2]          →   3     ([1, 2, 2])
[1, 2, 3, 2, 2]       →   4     ([2, 3, 2, 2])

ML context. "The longest period with at most k distinct things" is a common log question: the longest stretch of traffic served by at most two model versions (a clean A/B window), the longest session touching at most k product categories, the longest run of a training log with at most k distinct warning types. Recognising the story as a window problem is half the interview.


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 "Fruit Into Baskets"

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