Dsa
Graphs Dfs
Easy
Connected Components Size
Given an undirected graph represented as an adjacency list, write a program that computes the size of the largest connected component in the graph.
Input Format:
- The first line contains an integer n (number of nodes).
- The next n lines contain the adjacency list for each node. Each line starts with the node number followed by its neighbors separated by spaces.
Output Format:
- Print the size of the largest connected component.
Example:
Input:
5
0 1 2
1 0 2
2 0 1 3
3 2
4
Output:
4
Key concepts
graphsdfscomponents
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now