Dsa
Union Find
Easy
Social Media Connections
In a social media platform, users can connect with each other. Given a list of connections (friendships) between users, determine the number of distinct groups of users where users in the same group are connected either directly or indirectly.
Input:
- The first line contains an integer n (1 <= n <= 100), the number of users.
- The second line contains an integer m (0 <= m <= n*(n-1)/2), the number of friendship connections.
- Each of the next m lines contains two integers a and b, representing a friendship between user a and user b.
Output:
- Print the number of distinct groups of users.
Example:
Input:
4
4
0 1
1 2
2 3
3 0
Output:
1
Key concepts
union_findsocial_networkconnections
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