Code RoomAccount merge deduplication
MediumPrep Room Coding #1075

Account merge deduplication

CodingAlgorithms & data structuresMid–Senior~30 min

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.

0:00 of about 30 min
InputExpectedGot
[[["John","a@x.com","b@x.com"],["John","b@x.com"],["Mary","m@x.com"],["John","z@x.com"]]]3not run yetsample