Dsa
Union Find
Easy
Friendship Circles
In a community, friends can form circles of friendships. You are given pairs of friendships and need to determine the size of the largest friendship circle. Each person is represented by a unique integer ID.
Input format:
- The first line contains an integer F (1 ≤ F ≤ 10^5), the number of friendship pairs.
- The next F lines each contain two integers A and B, representing that person A is friends with person B.
Output format:
- Print the size of the largest friendship circle.
Example:
Input:
4
1 2
2 3
4 5
4 6
Output:
4
Key concepts
union_findfriendship
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