Number of Connected Components in an Undirected Graph

Medium 30 pts New · no attempts yet csharp

Number of Connected Components in an Undirected Graph — Fidelity Investments interview prep · Graphs

Classic interview problem #323.

Input (stdin)

Line 1: n nodes

Output (stdout)

Graph result (Number of Connected Components in an Undirected Graph)

Your program must read from stdin and write the answer to stdout (no extra debug text).

Examples

Sample
Input
5
Output
5
Static hints
  • Input format: Line 1: n nodes
  • DSA Interview 150 — Graphs
  • Problem #323
  • Frequently asked at Fidelity Investments
  • Graphs

Toolliyo Coach

Stuck? Get a nudge — not the answer

Progressive help: Nudge → Guide → Approach. Full solution stays behind the Solution tab.

Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details