VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 05: Binary search

Lesson 5.8 of 10 in this module Unrolled Pro

Koko Eating Bananas

The slowest eating speed that finishes every pile within h hours: a search on the answer. From trying every speed (O(max · n)), to a tighter starting point (still linear in the worst case), to binary search over speeds with an O(n) check (O(n log max)). Then huge piles and integer ceilings, real-valued speeds, and the ML twin: splitting a model's layers across k GPUs so the slowest stage is as fast as possible.

about 10 min 4 Python examples 2 quick checks

Problem. There are piles[i] bananas in pile i. Each hour, Koko picks one pile and eats up to k bananas from it; if the pile has fewer than k, she finishes it and waits out the hour. She has h hours (h ≥ len(piles)). Return the minimum integer speed k that lets her finish everything in time.

text
piles = [3, 6, 7, 11], h = 8         →   4
piles = [30, 11, 23, 4, 20], h = 5   →   30
piles = [30, 11, 23, 4, 20], h = 6   →   23

At speed k, pile p takes ceil(p / k) hours, so the total is hours(k) = Σ ceil(p / k). We want the smallest k with hours(k) ≤ h.

ML context. This is the shape of every capacity question: the smallest throughput, worker count or memory budget that meets a deadline. The minimum tokens per second per worker to process a dataset by morning, the fewest GPUs that serve a load at a target latency, the smallest stage size when splitting a model into pipeline stages (Change C). There's no array to search: you search the answer.


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 "Koko Eating Bananas"

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