Coding

Connected Components in an Undirected Graph

Determine the number of connected components in an undirected graph.

Input: n = 4, edges = [[0,1],[2,3]]

Output: 2

Explanation: The graph is split completely evenly into two distinct isolated components: nodes {0,1} and nodes {2,3}.

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