Merge Duplicate Member Accounts That Share Verified Emails

Last updated: November 29, 2026

Quick Overview

Each account is a list of verified email addresses. Two accounts belong to the same person if they share any email, directly or through a chain of accounts. Return the groups of account indices that belong to the same person.

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

0

0

0 solved


Each account is a list of verified email addresses. Two accounts belong to the same person if they share any email, directly or through a chain of accounts. Return the groups of account indices that belong to the same person.

Duplicate accounts hurt LinkedIn's graph quality, search, and trust systems. Interviewers use this to see union find with path compression, mapping emails to a first owner, and reasoning about transitive merges.

What the Interviewer Expects
  • Maps each email to the first account index that owned it
  • Unions accounts that share an email using union find
  • Applies path compression and union by size or rank
  • Collects groups by root and returns them deterministically
  • Explains near-linear complexity with inverse Ackermann
Key Topics to Cover
union find
disjoint set
transitive closure
entity resolution
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 run this over hundreds of millions of accounts in Spark?
  • What if some emails are shared legitimately, such as a team inbox?
  • How do you support adding a new account incrementally?
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: accounts[i] is a list of emails, already normalized (lowercased, trimmed). Output: list of sorted index lists, one per person, sorted by first index. Every account appears in exactly one grou...

High-Level Design

Union find over account indices. Walk every email; the first time an email appears, record its owner; afterwards union the current account with that owner. Because union is transitive, a chain A-B thr...


Submit Your Answer
Markdown supported