FDEInterviews logoFDE/Interviews
Coding & DSA / 89
mediumOpenAIGoogleAmazon

Simulate an infection spreading across a grid over time

A grid where some cells start infected, and each step every infected cell infects its orthogonal neighbors. How many steps until everything is infected, or -1 if some cell is unreachable? This is rotting oranges in disguise, and the multi-source BFS framing is what they want to hear.

Updated Aug 2026 · Grounded in real Forward Deployed Engineer interview loops and written to a senior-engineer editorial bar.

A grid where some cells start infected, and each step every infected cell infects its orthogonal neighbors. How many steps until everything is infected, or -1 if some cell is unreachable? This is rotting oranges in disguise, and the multi-source BFS framing is what they want to hear.

Unlock the other 466 answers · ₹2,000 / $25Your progress and mastery stay saved · 6 months · one payment · no auto-renew
UP NEXT ON YOUR JOURNEY
FEDITOR'S NOTE

The tell that separates a pass from a stall is recognizing this is multi-source BFS, not a single-source loop run once per seed. Seed every infected cell into the queue at distance 0 and the wavefront expands in lockstep; the last cell dequeued gives the answer, and any cell never reached gives -1.

DISCUSSION · 0

No comments yet — be the first to share your approach.