Question bank › Union Find
Dsa Union Find Medium

Friend Circle Connections

You are given a list of friendships represented as pairs of integers where each integer represents a person. Implement a function to determine the number of unique friend circles. A friend circle is a group of people who are directly or indirectly connected through friendships. Input the number of friendships followed by the pairs of friendships. Input format: N A1 B1 A2 B2 ... AN BN Where N is the number of friendships and Ai Bi are the pairs of friends. Output format: An integer representing the number of unique friend circles. Example: Input: 5 0 1 1 2 3 4 2 3 4 5 Output: 3

Key concepts

union_findgraphsdisjoint_sets

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.