Rotting Oranges — Multi-Source BFS
Find minimum minutes until all oranges rot. Multi-source BFS: push all initially-rotten oranges into queue simultaneously, BFS layer by layer.
webcoderspeed.com
7 articles
Find minimum minutes until all oranges rot. Multi-source BFS: push all initially-rotten oranges into queue simultaneously, BFS layer by layer.
For each cell find distance to nearest 0. Multi-source BFS from all 0s simultaneously gives optimal O(m*n) solution.
Fill each empty room with distance to nearest gate. Multi-source BFS from all gates (0) simultaneously, walls (-1) are barriers.
Find cells that can flow to both Pacific and Atlantic oceans. Run DFS backwards from each ocean border, find intersection.
Find the water cell farthest from any land. Multi-source BFS from all land cells gives each water cell its min distance to land.
Find minutes until all oranges rot using multi-source BFS starting from all initially rotten oranges simultaneously.
Fill each empty room with its distance to nearest gate using simultaneous multi-source BFS from all gates.