Question bank › Union Find
Dsa Union Find Easy

Team Collaborations

You are managing a list of teams where each team consists of members identified by unique ids. Sometimes, teams collaborate with each other, which means the members of those teams can be considered as one group. Write a program to find out how many distinct teams (groups of members) exist after all collaborations have been recorded. Input: The first line contains an integer c (1 <= c <= 1000), the number of collaborations. The next c lines contain two integers a and b (members of two collaborating teams). Output: Print the number of distinct teams after all collaborations. Example: Input: 5 1 2 2 3 4 1 5 6 6 5 Output: 3

Key concepts

union_findteamworkcollaboration

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.