8. Number of Provinces
Medium

Problem Statement

There are n cities. Return the total number of provinces (connected components).

Examples

1Example 1
Input:
[ [ [ 1, 1, 0 ], [ 1, 1, 0 ], [ 0, 0, 1 ] ] ]
Output:
2
2Example 2
Input:
[ [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ] ]
Output:
3
3Example 3
Input:
[ [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ] ]
Output:
1
Loading...

Sign in to Run Code and Submit