Merge Duplicate User Accounts That Share Phone or Email

Last updated: November 29, 2026

Quick Overview

Account records each have a user ID and a list of contact identifiers (emails and phone numbers). Two records belong to the same person if they share any identifier, directly or through a chain. Return the merged groups of record IDs with their combined identifiers.

TikTok
Coding & Algorithms
Data Engineer
TikTok
November 29, 2026
Data Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Account records each have a user ID and a list of contact identifiers (emails and phone numbers). Two records belong to the same person if they share any identifier, directly or through a chain. Return the merged groups of record IDs with their combined identifiers.

TikTok's integrity and growth teams deduplicate accounts for fraud detection and for accurate user counts, so this union-find question shows up for backend and data engineering screens. The interviewer checks that you can union through shared identifiers transitively and keep near-linear complexity.

What the Interviewer Expects
  • Models identifiers and records so shared identifiers link records transitively
  • Implements union-find with path compression and union by size or rank
  • Avoids an O(n^2) pairwise comparison of records
  • Collects groups and their identifier sets at the end
  • Discusses normalizing identifiers (lowercase emails, E.164 phones)
Key Topics to Cover
union find
connected components
entity resolution
hash maps
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you do this in a distributed batch job over billions of records?
  • Shared identifiers like a company help-desk phone would merge unrelated users; how do you guard against that?
  • How would you support incremental merges as new records arrive?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: list of (record_id, identifiers).
  • Output: list of (sorted record IDs, sorted identifiers) per merged person.
  • Identifiers should be normalized before matching....
High-Level Design

Treat each record as a node. Keep a map from identifier to the first record that used it. When a later record uses the same identifier, union the two records. Union-find makes the transitive closure a...


Submit Your Answer
Markdown supported