← Anthropic Interview Insights

Anthropic·Software Engineer·Online Assessment (OA)·Intermediate

IntermediatePending
Jun 2026

Summary

Took an online assessment for a Software Engineer role at Anthropic. One coding problem on merging accounts, ran out of time, a couple edge cases blew up, and ended up with 800 out of 1000. Recruiter emailed me about two hours later.

Questions Asked (1)

Q1

Given a list of accounts where each account contains a name and a set of emails, merge accounts that share at least one email address.

Algorithms & Data Structures
Author's notes

Did not finish.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a graph where each email is a node and accounts are connected if they share an email. Use union-find (disjoint set union) to efficiently merge accounts, then group emails by their root representative. Alternatively, use DFS/BFS on the graph, but union-find is more efficient for this merging task.

Pro tip: Mention that the order of emails within each merged account doesn't matter, but you should sort them for consistent output. Also, clarify that the name can be taken from any account in the merged set, as names are assumed consistent for the same person.

1. Clarify requirements and edge cases

Ask about input size, whether names are consistent for the same person, and if the output order matters. Confirm that accounts with the same name but no shared emails should not be merged.

2. Choose data structures

Use a hash map to map each email to an account index or directly to a union-find parent. Use union-find to track connected components of accounts.

3. Build the union-find structure

Iterate through each account and its emails. For each email, if it's seen before, union the current account with the account that first contained that email. Otherwise, record the email's owner.

4. Group emails by root

After processing all accounts, traverse the union-find to find the root for each account. Collect all emails for each root into a set to deduplicate, and pick a name (e.g., the first account's name).

5. Format and return the result

For each root, create a list with the name followed by the sorted list of unique emails. Return the list of merged accounts.

Key Points to Mention

  • Union-Find (Disjoint Set Union) with path compression and union by rank for near O(1) operations.
  • Hash map to map email to account index or parent for efficient lookups.
  • Time complexity: O(N * α(N)) where N is total number of emails, effectively linear.
  • Space complexity: O(N) for the union-find structure and hash map.
  • Handling of duplicate emails within the same account (should be deduplicated).
  • Alternative approach: graph traversal (DFS/BFS) 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.