Code Room
CodingMediumcod-g507
Subject Union findLevel Mid–Senior~30 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

You're deduplicating user accounts. Each account is a list whose first element is a display name and remaining elements are emails. Two accounts belong to the same person if they share at least one email (this is transitive: A~B and B~C means A, B, C are the same person). Different people may share the same name. Return the number of distinct people after merging. There are at most 1000 accounts.

Implement
count_account_groups(accounts: list[list[str]]) → int
Examples
in[[["John","a@x.com","b@x.com"],["John","b@x.com"],["Mary","m@x.com"],["John","z@x.com"]]]out3
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.