Merge Contact Cards That Share Any Phone Number or Email
Last updated: November 29, 2026
Quick Overview
Each contact card has a display name and a list of identifiers (emails and phone numbers). Two cards belong to the same person if they share any identifier, directly or through a chain. Merge them and return each person's name with their sorted unique identifiers.
Apple
November 29, 20260
0
0 solved
Each contact card has a display name and a list of identifiers (emails and phone numbers). Two cards belong to the same person if they share any identifier, directly or through a chain. Merge them and return each person's name with their sorted unique identifiers.
Contacts unification across iCloud, iMessage and third-party accounts is a real Apple problem, and this is a classic union-find onsite question. The interviewer checks transitive merging, path compression and how you pick a name for the merged card.
What the Interviewer Expects
- Treat identifiers as nodes and union all identifiers on a card
- Use union-find with path compression and union by size
- Group identifiers by root and attach a name
- Normalize phone numbers before comparing
- Explain near-linear complexity
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
- Phone numbers come in different formats such as +1 (408) 555-0100; how do you normalize?
- Two people share a family landline; how do you avoid merging them?
- Support unmerging when a user splits a card.
- Cards arrive incrementally from sync; can you merge online?
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, [identifiers]). Output: list of (name, sorted_identifiers), one per person, sorted by first identifier. The merged name is taken from the earliest card in the group. Cards wi...
High-Level Design
Assign every identifier to a disjoint-set node. For each card, union all its identifiers with the first one, and remember which card first introduced each identifier. Afterwards, find the root of each...