Account merge deduplication
Your task
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: AB and BC 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.
Examples
count_account_groups(accounts: list[list[str]]) -> intExample 1
Input
count_account_groups([["John", "a@x.com", "b@x.com"], ["John", "b@x.com"], ["Mary", "m@x.com"], ["John", "z@x.com"]])Output
3