Question bank › Union Find
Dsa Union Find Easy

Island Connections

In a simulation of islands connected by bridges, each island is identified by an integer. Given a list of bridges, determine how many distinct groups of connected islands exist after all the bridges are built. Input: The first line contains an integer B (1 ≤ B ≤ 1000) representing the number of bridges. The next B lines each contain two integers a and b, indicating that there is a bridge connecting islands 'a' and 'b'. Output: Output a single integer representing the number of distinct island groups. Example: Input: 4 1 2 2 3 4 5 5 6 Output: 3

Key concepts

union_findislandsconnectivity

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.