Dsa
Union Find
Medium
Corporate Syndicate Leaders
N employees are forming syndicates. Initially, each employee is their own syndicate. When two syndicates merge, the leader of the new syndicate is chosen based on size: the syndicate with more members absorbs the smaller one. If both have the same number of members, the one whose current leader's name is lexicographically smaller wins. Given a sequence of MERGE operations and LEADER queries, output the leader's name for each query.
Input format:
Line 1: N (number of employees), Q (number of operations).
Next N lines: Names of employees 0 to N-1 (single words).
Next Q lines: 'MERGE u v' or 'LEADER u'.
Example:
3 2
Alice
Bob
Charlie
MERGE 0 1
LEADER 1
Output: Alice
Key concepts
union_findmerging_rulesstrings
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