Problems > The Rot Spreads > Editorial

The Rot Spreads — Solution & Editorial

Back to the Problem

Multi-source BFS: seed the queue with every rotten cell at time 0; the answer is the largest BFS time, provided no fresh cell is left unvisited.

Complexity: O(NM)