Code Room
CodingHardcod-g022
Subject Connected componentsLevel Senior–Staff~40 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

You are given accounts, where accounts[i] = [name, email1, email2, ...]. Two accounts belong to the same person if they share at least one email; a person may have multiple accounts and any two with a common email merge transitively. Return the merged accounts: each as [name, sorted_unique_emails...], where the name is the name from any of the merged accounts (they share the same name). Return the list of merged accounts sorted ascending by their full [name, emails...] list representation.

Implement
merge_accounts(accounts: list[list[str]]) → list[list[str]]
Examples
in[[["John","a@x.com","b@x.com"],["John","b@x.com","c@x.com"],["Mary","m@x.com"]]]out[["John","a@x.com","b@x.com","c@x.com"],["Mary","m@x.com"]]
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.