Number of Provinces
Try to solve the Number of Provinces problem.
We'll cover the following
Statement
Given cities
, where cities[i][j]
cities[i][j]
Note: If city
is directly connected to city and city is directly connected to city , then city is indirectly connected to city .
The task is to return the total number of groups of connected cities directly or indirectly. These groups are referred to as
Constraints:
cities.length
cities[i].length
, wherecities[i][j]
is eitheror . cities[i][i]
cities[i][j]
cities[j][i]
Examples
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.