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.
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.
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.
No comments yet — be the first to share your approach.
