VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 11: Graphs

Lesson 11.5 of 16 in this module Unrolled Pro

Rotting Oranges

Every minute, rotten oranges rot their fresh neighbours; how many minutes until none are fresh? From simulating minute by minute with a full grid scan each time (O((R·C)²)), to multi-source BFS that starts from every rotten orange at once and spreads level by level (O(R·C)). Then fresh oranges that can never be reached, the distance from every cell to its nearest source, different spreading speeds (Dijkstra), and the ML twin: how many hops it takes for information or labels to spread through a graph.

about 10 min 4 Python examples 2 quick checks

Problem. A grid holds 0 (empty), 1 (fresh orange) and 2 (rotten orange). Every minute, each fresh orange that is 4-directionally adjacent to a rotten one becomes rotten. Return the minimum number of minutes until no fresh orange remains, or −1 if some fresh orange can never rot.

text
2 1 1        minute 1: 2 2 1     minute 2: 2 2 2     minute 3: 2 2 2     minute 4: 2 2 2
1 1 0                  2 1 0               2 2 0               2 2 0               2 2 0
0 1 1                  0 1 1               0 1 1               0 2 1               0 2 2    →   4

The rot spreads one step per minute from every rotten orange simultaneously. That's BFS with many sources: put all of them in the queue at time 0, and each BFS level is one minute.

ML context. Spreading processes on graphs: how many hops until a message (or a label, in label propagation) reaches every node, how fast a model update rolls out through a fleet where each upgraded server upgrades its neighbours, the distance from each pixel to the nearest edge or annotated point (a distance transform, used for weighting losses near boundaries). All are multi-source BFS (Changes B and D).


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 "Rotting Oranges"

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