Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Number of Provinces
Bookmark
DFS
BFS
Union Find
Input
2 Provinces
3 Provinces
1 Province
2 Provinces
Custom
isConnected
=
[[1,1,0],[1,1,0],[0,0,1]]
isConnected Matrix
0
1
2
0
1
1
0
1
1
1
0
2
0
0
1
City Connections
0
1
2
Traversal State
visited
F
0
F
1
F
2
call stack
empty
Legend:
Standard
Checking
Active
Connected
isConnected Matrix
0
1
2
0
1
1
0
1
1
1
0
2
0
0
1
City Connections
0
1
2
Traversal State
visited
F
0
F
1
F
2
call stack
empty
Legend:
Standard
Checking
Active
Connected
isConnected Matrix
0
1
2
0
1
1
0
1
1
1
0
2
0
0
1
City Connections
0
1
2
Traversal State
visited
F
0
F
1
F
2
call stack
empty
Provinces: 0
Legend:
Standard
Checking
Active
Connected
isConnected Matrix
0
1
2
0
1
1
0
1
1
1
0
2
0
0
1
City Connections
0
1
2
Traversal State
visited
T
0
F
1
F
2
call stack
0
Provinces: 0
Legend:
Standard
Checking
Active
Connected
isConnected Matrix
0
1
2
0
1
1
0
1
1
1
0
2
0
0
1
City Connections
0
1
2
Traversal State
visited
T
0
T
1
F
2
call stack
0
1
Provinces: 0
Legend:
Standard
Checking
Active
Connected
isConnected Matrix
0
1
2
0
1
1
0
1
1
1
0
2
0
0
1
City Connections
0
1
2
Traversal State
visited
T
0
T
1
F
2
call stack
0
Provinces: 0
Legend:
Standard
Checking
Active
Connected
isConnected Matrix
0
1
2
0
1
1
0
1
1
1
0
2
0
0
1
City Connections
0
1
2
Traversal State
visited
T
0
T
1
F
2
call stack
empty
Provinces: 0
Legend:
Standard
Checking
Active
Connected
isConnected Matrix
0
1
2
0
1
1
0
1
1
1
0
2
0
0
1
City Connections
0
1
2
Traversal State
visited
T
0
T
1
F
2
call stack
empty
Provinces: 1
Legend:
Standard
Checking
Active
Connected
isConnected Matrix
0
1
2
0
1
1
0
1
1
1
0
2
0
0
1
City Connections
0
1
2
Traversal State
visited
T
0
T
1
T
2
call stack
2
Provinces: 1
Legend:
Standard
Checking
Active
Connected
isConnected Matrix
0
1
2
0
1
1
0
1
1
1
0
2
0
0
1
City Connections
0
1
2
Traversal State
visited
T
0
T
1
T
2
call stack
empty
Provinces: 1
Legend:
Standard
Checking
Active
Connected
isConnected Matrix
0
1
2
0
1
1
0
1
1
1
0
2
0
0
1
City Connections
0
1
2
Traversal State
visited
T
0
T
1
T
2
call stack
empty
Provinces: 2
Legend:
Standard
Checking
Active
Connected
algo
master
.
io
Step:
Given 3 cities with connection matrix. Find the number of provinces.
0 / 22
Input
2 Provinces
3 Provinces
1 Province
2 Provinces
Custom
isConnected
=
[[1,1,0],[1,1,0],[0,0,1]]
0 / 22
algo
master
.
io
Step:
Given 3 cities with connection matrix. Find the number of provinces.