Loading problem…
You are given an n × n symmetric matrix isConnected. An entry of 1 means those two cities are directly connected; 0 means they are not. Each city is connected to itself.
A province is one maximal group of cities reachable from one another through direct or indirect connections. Return the number of provinces. An isolated city is a province of its own.
Do not modify the matrix. Matrix rows describe cities and columns describe neighbors; this is a graph adjacency matrix, not a grid traversal problem.
Example 1:
Example 2:
Example 3: