Dsa
Union Find
Easy
Friends Network
You are tasked with managing a social network where people can be friends with each other. Given a list of pairs indicating friendships, your goal is to determine how many distinct friend groups exist after processing all friendships. A friend group is defined as a group of people where each person is directly or indirectly connected through friendships.
Example Input:
5
1 2
2 3
4 5
Example Output:
2
Key concepts
union_findsocial_network
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