Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
01 Matrix
Bookmark
BFS per Cell
Multi-source
DP
Input
Example 1
Example 2
Corner zeros
Single zero
Custom
grid
=
[[0,0,0],[0,1,0],[0,0,0]]
max dist
0
distance
0
0
0
0
0
0
0
0
0
0
queue
a separate BFS out of every 1-cell
max dist
0
distance
0
0
0
0
0
0
0
0
0
0
queue
a separate BFS out of every 1-cell
max dist
0
distance
0
0
0
0
0
0
0
0
0
0
queue
(0,1)
needs its own BFS
max dist
0
distance
0
0
0
0
0
0
0
0
0
0
queue
(1,1)
needs its own BFS
max dist
0
distance
0
0
0
0
0
0
0
0
0
0
queue
(1,1)
at dist 0 expands outward
max dist
0
distance
0
0
0
0
0
0
0
0
0
0
queue
1,2
front
max dist
0
distance
0
0
0
0
0
0
0
0
0
0
queue
1,2
1,0
front
(2,1)
is unvisited - set its distance
max dist
0
distance
0
0
0
0
0
0
0
0
0
0
queue
1,2
1,0
2,1
0,1
front
max dist
0
distance
1
0
0
0
0
0
0
0
0
0
queue
1,0
2,1
0,1
front
(1,2)
at distance 1
max dist
1
distance
1
0
0
0
0
1
0
0
0
0
queue
(2,0)
needs its own BFS
max dist
1
distance
0
0
0
0
0
1
0
0
0
0
queue
return dist
algo
master
.
io
Step:
Run a BFS out of every 1-cell until it reaches a 0
0 / 27
Input
Example 1
Example 2
Corner zeros
Single zero
Custom
grid
=
[[0,0,0],[0,1,0],[0,0,0]]
0 / 27
algo
master
.
io
Step:
Run a BFS out of every 1-cell until it reaches a 0