Multi-Source BFS: Rotting Oranges

medium
Unit 14 · Strings & BFS0/3 to milestone

In a grid, 0 is empty, 1 a fresh orange and 2 a rotten one. Each minute, fresh oranges next to (up/down/left/right) a rotten one rot. Return the minutes until no fresh orange remains, or -1 if some can never rot.

Use multi-source BFS: start the queue with every rotten orange at once. Don't modify the input grid.

#bfs#grids2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Multi-Source BFS: Rotting Oranges · TechGradify