Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Number of Islands
Bookmark
DFS
BFS
Union-Find
Input
Example 1
5 islands
Single Island
All Water
Custom
grid
=
[["1","1","0","0"],["1","1","0","0"],["0","0","1","0"],["0","0","0","1"]]
Islands Found:
0
Call depth
0
0
1
2
3
0
1
2
3
1
1
0
0
1
1
0
0
0
0
1
0
0
0
0
1
call stack
Islands Found:
0
Call depth
0
0
1
2
3
0
1
2
3
1
1
0
0
1
1
0
0
0
0
1
0
0
0
0
1
call stack
Islands Found:
1
Call depth
3
0
1
2
3
0
1
2
3
V
1
0
0
V
1
0
0
0
0
1
0
0
0
0
1
(0,0)
(1,0)
(0,0)
top
call stack
Islands Found:
1
Call depth
5
0
1
2
3
0
1
2
3
V
V
0
0
V
V
0
0
0
0
1
0
0
0
0
1
(0,0)
(1,0)
(1,1)
(0,1)
(1,1)
top
call stack
Islands Found:
1
Call depth
4
0
1
2
3
0
1
2
3
V
V
0
0
V
V
0
0
0
0
1
0
0
0
0
1
(0,0)
(1,0)
(1,1)
(1,2)
top
call stack
Islands Found:
1
Call depth
2
0
1
2
3
0
1
2
3
V
V
0
0
V
V
0
0
0
0
1
0
0
0
0
1
(0,0)
(0,1)
top
call stack
Islands Found:
1
Call depth
0
0
1
2
3
0
1
2
3
V
V
0
0
V
V
0
0
0
0
1
0
0
0
0
1
call stack
Islands Found:
2
Call depth
2
0
1
2
3
0
1
2
3
V
V
0
0
V
V
0
0
0
0
V
0
0
0
0
1
(2,2)
(3,2)
top
call stack
Islands Found:
2
Call depth
0
0
1
2
3
0
1
2
3
V
V
0
0
V
V
0
0
0
0
V
0
0
0
0
1
call stack
Islands Found:
3
Call depth
2
0
1
2
3
0
1
2
3
V
V
0
0
V
V
0
0
0
0
V
0
0
0
0
V
(3,3)
(4,3)
top
call stack
Islands Found:
3
Call depth
0
0
1
2
3
0
1
2
3
V
V
0
0
V
V
0
0
0
0
V
0
0
0
0
V
call stack
algo
master
.
io
Step:
Start: count islands using DFS
0 / 81
Input
Example 1
5 islands
Single Island
All Water
Custom
grid
=
[["1","1","0","0"],["1","1","0","0"],["0","0","1","0"],["0","0","0","1"]]
0 / 81
algo
master
.
io
Step:
Start: count islands using DFS