Merge Duplicate Customer Accounts Sharing a Phone or Email
Last updated: November 29, 2026
Quick Overview
Each customer record has an ID and a list of contact identifiers (phones and emails). Two records belong to the same person if they share any identifier, directly or through a chain; return the groups of record IDs that should be merged.
Flipkart
November 29, 20260
0
0 solved
Each customer record has an ID and a list of contact identifiers (phones and emails). Two records belong to the same person if they share any identifier, directly or through a chain; return the groups of record IDs that should be merged.
Flipkart's identity and fraud teams deal with users who sign up repeatedly to farm first order offers. This onsite question checks whether you model transitive sharing as connected components and pick union find with path compression.
What the Interviewer Expects
- Recognize transitive grouping as connected components
- Use union find keyed by identifier owner, or a graph plus BFS
- Apply path compression and union by size
- Return deterministic, sorted groups
- Discuss near linear O(N * alpha(N)) 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
- How would you handle a shared office phone number that links thousands of unrelated accounts?
- How would you run this incrementally as new sign ups arrive?
- How would you do this at the scale of hundreds of millions of accounts?
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
(record_id, identifiers); identifiers are normalized phones and lowercase emails. - Two records merge if they share an identifier or are linked through a chain of shared identifiers...
High-Level Design
Treat records as nodes. Rather than comparing all pairs, map each identifier to the first record that used it. When a later record uses the same identifier, union the two records. Union find with path...