Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Watch how corruption spreads through a grid. This is a Multi-source Breadth-First Search (BFS) problem, where multiple "rotten" sources contaminate adjacent fresh cells simultaneously.
Every minute, the rot spreads 1 unit distance in all 4 directions. BFS ensures we find the earliest possible time for each orange to rot.
We initialize a queue with all initially rotten oranges. This allows them to "race" outwards simultaneously, calculating the global time.