Coding

Perform a depth-first search on a matrix to find connected components.

Given an n x n matrix where isConnected[i][j] = 1 if the ith node and the jth node are directly connected, and 0 otherwise, return the total number of connected components.

Input: isConnected = [[1,0,0],[0,1,0],[0,0,1]]

Output: 3

Explanation: There are no connections between any of the nodes, resulting in 3 completely isolated subgraphs.

Was asked at

Practice this question with AI

First session is free - no credit card required.

Go Premium

More interviews, more skills, more success.

No answers yet

Be the first to share your approach to this question

Practice More Questions