← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Meta SWE coding round, one question the whole time and it was the accounts merging problem. Union-Find heavy, not a vibe if you haven't drilled that pattern recently.

Questions Asked (1)

Q1

Given a list of accounts where each entry has a name followed by one or more emails, merge all accounts that share at least one email address. Return the merged accounts with emails sorted lexicographically, each preceded by the account name.

Algorithms & Data Structures
Author's notes

I knew Union-Find was the move but fumbled the setup for a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a graph where emails are nodes and accounts are edges, then find connected components. Use Union-Find (Disjoint Set Union) to efficiently merge accounts sharing emails, then collect and sort emails for each component.

Pro tip: Emphasize the trade-offs between Union-Find and BFS/DFS, and mention that Union-Find with path compression and union by rank gives near-constant time operations, which is ideal for large datasets like those at Meta.

1. Clarify and Restate

Confirm input format, output requirements, and edge cases (e.g., duplicate emails, accounts with no shared emails).

2. Choose Data Structure

Select Union-Find for efficient merging, or graph traversal (BFS/DFS) if preferred. Explain why.

3. Map Emails to Accounts

Use a hash map to associate each email with an account index or node, enabling quick union operations when duplicates are found.

4. Merge and Collect

Union accounts sharing emails, then group emails by their root parent. Sort emails lexicographically for each group.

5. Format Output

Construct the final list with the account name followed by sorted emails, ensuring no duplicates and correct ordering.

Key Points to Mention

  • Union-Find with path compression and union by rank for near O(1) operations.
  • Using a hash map to map emails to account indices for efficient duplicate detection.
  • Time complexity: O(N α(N) + M log M) where N is number of emails and M is max emails per account.
  • Space complexity: O(N) for the Union-Find structure and hash map.
  • Handling edge cases: accounts with no shared emails, duplicate emails within an account, and empty input.
  • Alternative approach: BFS/DFS on a graph where emails are nodes and accounts are edges, but Union-Find is more efficient for merging.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.