Merge Customer Accounts That Share a Card or Phone

Last updated: November 29, 2026

Quick Overview

Given customer accounts with lists of identifiers such as card fingerprints and phone numbers, group together all accounts linked directly or transitively by a shared identifier and return the groups that contain more than one account.

DoorDash
Coding & Algorithms
Software Engineer
DoorDash
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Given customer accounts with lists of identifiers such as card fingerprints and phone numbers, group together all accounts linked directly or transitively by a shared identifier and return the groups that contain more than one account.

Promo abuse at DoorDash often shows up as many accounts tied together by a reused card or phone number. This union find question checks whether you can model transitive linking efficiently and talk about how the same idea feeds a trust and safety pipeline.

What the Interviewer Expects
  • Model accounts as nodes and shared identifiers as edges
  • Use union find with path compression and union by size
  • Map each identifier to the first account that used it
  • Return only multi-account groups, in a deterministic order
  • Compare with BFS over an explicit graph
Key Topics to Cover
union find
connected components
fraud detection
hashing
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 weight links so a shared office phone does not merge hundreds of accounts?
  • How would you maintain groups incrementally as new accounts sign up?
  • How would you split a group if a link is later found to be wrong?
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 (account_id, [identifiers]).
  • Two accounts are linked if they share any identifier; linking is transitive.
  • Output: sorted list of groups (each a sorted list of account ids) with ...
High-Level Design

Give each account an index in a disjoint set. Walk every identifier; the first time we see it, remember its owner index; afterwards, union the current account with that owner. This adds at most one un...


Submit Your Answer
Markdown supported