🧠 Before you code — what pattern fits?
There are n cities. isConnected[i][j] = 1 means cities i and j are directly connected. A province is a group of directly or indirectly connected cities. Return the total number of provinces.
[[1,1,0],[1,1,0],[0,0,1]] → 2
[[1,0,0],[0,1,0],[0,0,1]] → 3
🎬 Video explanation · take U forward
Your solution runs against 2 unit tests, including edge and large-value cases.
Loading...
Test console · 2 unit tests
Submit your code to run it against all 2 unit tests. Results appear here.
JavaScript, TypeScript & Python run sandboxed in your browser; other languages run on the execution server. Your code is saved locally as you type.