Question bank › Union Find
Dsa Union Find Medium

Classroom Seat Allocation

A school needs to allocate seats for students in classrooms based on mutual friendships. Each classroom can accommodate multiple groups of friends. If a student is friends with another, they must sit in the same classroom. Input Format: The first line contains an integer n, the number of students (1 ≤ n ≤ 500). The next line contains an integer m, the number of friendship pairs (0 ≤ m ≤ 2000). The following m lines each contain two integers a and b, indicating that student a is friends with student b. Output Format: Print the minimum number of classrooms needed such that all friends sit together. Example: Input: 4 3 1 2 2 3 4 1 Output: 2

Key concepts

union_findclassroomsenrollment

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.