Link: https://leetcode.com/problems/01-matrix/
Solution:
Topics: BFS
Intuition
This is a nice little BFS problem. Basically this is a multi-node BFS where we populate the queue with all positions that contain 0
, and fill in the current level for each node.
Implementation
Mnemonic
Imagine a virus spreading from multiply locations
Visual
Review 1
Nice and simple BFS problem. I did solve this by modifying the original array in place instead of using a visited set, but maybe this is overkill because the bfs queue is o(m*n)
anyway, so might as well keep it simple and use a visited set.