Merge Duplicate Customer Profiles That Share an Email Address
Last updated: November 29, 2026
Quick Overview
Each customer profile record has a name and a list of email addresses; two records belong to the same person if they share any email. Merge the records and return each person as the name followed by their sorted unique emails.
Amazon
November 29, 20260
0
0 solved
Each customer profile record has a name and a list of email addresses; two records belong to the same person if they share any email. Merge the records and return each person as the name followed by their sorted unique emails.
Identity resolution is a real problem for Amazon's customer data, where sign-ups, guest checkouts, and acquisitions create duplicate profiles. The interviewer looks for union find keyed by email rather than by record, and careful handling of the output format.
What the Interviewer Expects
- Union emails within each record to the record's first email
- Use a dictionary based DSU keyed by email
- Group emails by root and sort them
- Attach the owning name
- Discuss O(E log E) for E total emails
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Two different people can share a name; why does keying by name break?
- What if the same email appears with two different names?
- How would you run this over billions of records (connected components in Spark)?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of [name, email1, email2, ...]. Output: list of [name, sorted emails...], one per merged person, any order (I sort for determinism). Assume an email always belongs to one name....
High-Level Design
Treat each email as a node. Within a record, every email belongs to the same person, so union each one with the record's first email. Records that share an email get connected through it.
After proce...