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.

Community Answers

1 answer from the community

Unlock Full Access

Answer any un-answered question from our database to unlock all community answers for 30 days.

Give & Take

Practice More Questions

1 answer published. Last candidate submission on May 21 2026, 2:11am PDT. Interview question asked to Software Engineers interviewing at Strava, Spotify, Poshmark and other companies. Original question asked: Connected Components in an Undirected Graph. Question last reported by a candidate interviewing at Ninjacart for a Software Engineer interview on Jun 22 2026, 5:16am PDT.