Merge Customer Profiles That Share an Email or Phone Number

Last updated: November 29, 2026

Quick Overview

Given customer profiles, each with an id, a list of emails and a list of phone numbers, merge any profiles that share at least one normalized email or phone, transitively. Return the groups of profile ids.

Walmart Labs
Coding & Algorithms
Software Engineer
Walmart Labs
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Given customer profiles, each with an id, a list of emails and a list of phone numbers, merge any profiles that share at least one normalized email or phone, transitively. Return the groups of profile ids.

Identity resolution matters at Walmart, where the same shopper may have a Walmart.com account, a pharmacy profile and a Walmart+ membership. In the onsite coding round the interviewer looks for union find with path compression and attention to normalizing contact keys before matching.

What the Interviewer Expects
  • Identify the transitive grouping as connected components
  • Use union find with path compression and union by rank
  • Normalize emails and phone numbers before matching
  • Keep emails and phones in separate key namespaces
  • Return deterministic group ordering
Key Topics to Cover
union find
entity resolution
normalization
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 support un-merging when a customer reports a wrong link?
  • What if one phone number is shared by thousands of profiles, like a store landline?
  • How would you run this as a batch job over 500 million profiles?
  • How would you add fuzzy matching on names and addresses?
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 (profile_id, emails, phones). Two profiles belong together if they share a contact key, and grouping is transitive: A shares an email with B, and B shares a phone with C, so all three...

High-Level Design

Treat each profile as a node. Keep a dict owner from a normalized key to the first profile that used it. When a later profile has the same key, union the two. Prefixing keys with e or p stops an...


Submit Your Answer
Markdown supported

Related Questions