Question bank › Union Find
Dsa Union Find Warm-up

Library Connections

In a library, books are represented by integers from 0 to n-1. Given a list of connections that indicate how books are related, determine the number of distinct groups of related books in the library. Input Format: - The first line contains an integer n (1 ≤ n ≤ 100). - The second line contains an integer m (0 ≤ m ≤ 10^4) representing the number of connections. - The following m lines each contain two integers a and b (0 ≤ a, b < n) representing a connection between book a and book b. Output Format: - Print the number of distinct groups of related books. Example: Input: 3 2 0 1 1 2 Output: 1

Key concepts

union_findlibraryconnections

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