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.

Practice More Questions

1 answer published. Last candidate submission on May 21 2026, 2:11am PDT. Interview question asked to Software Engineers interviewing at Steem, PieSync, Garmin and other companies. Original question asked: Connected Components in an Undirected Graph. Question last reported by a candidate interviewing at Workday for a Software Engineer interview on May 29 2026, 12:24pm PDT.