Search⌘ K
AI Features

Number of Provinces

Explore how to determine the number of connected provinces from an adjacency matrix of cities. This lesson helps you understand direct and indirect connections, develop an optimal graph traversal approach, and apply it to coding interviews. Gain skills to solve this classic challenge efficiently.

Statement

Given nn cities, some are directly connected, and others are not. You are given an n×nn \times n matrix called cities, where cities[i][j] =1= 1 means city ithi^{th} and city ...