Deduplicate account sign-ups by email and phone
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Airbnb's coding round, last asked Apr 2026. It tests hash set, strings and simulation.
A sign-up service processes account registrations one at a time, in the order they arrive. You get three lists of the same length n: names, emails and phones. Index i of each list describes account i.
Implement:
register_accounts(names: list[str], emails: list[str], phones: list[str]) -> list[bool]
Return a list where entry i is True if account i registers successfully and False if it is a duplicate.
Rules
- An account registers only if its email is not claimed by an earlier registered account and its phone is not claimed by an earlier registered account.
- A duplicate account claims nothing. Its email and phone do not block later accounts.
-
namesis part of the record but is never used to detect duplicates. - Emails and phones are checked separately: an email only collides with emails, a phone only with phones.
- An empty string (or
None) means the field was not given. It never collides. - Raise
ValueErrorif the three lists have different lengths.
Part 2: normalization
Real users type the same identifier in different ways. Before checking, normalize:
- emails: trim surrounding spaces and compare case-insensitively;
- phones: keep only the digits (so
"+1 (415) 555-0100"equals"14155550100").
Example
Output: [True, True, False, False, True].
Constraints
-
0 <= n <= 10^5; each email and phone is at most 100 characters. - Aim for O(n) time for typical string lengths. State the time and space complexity.
Clarifying questions
- Is an account with both fields empty always registered, since nothing collides?
- In Part 2, should an email that is only spaces count as empty after trimming? And a phone with no digits?
- Should a duplicate's name be used anywhere, such as in a report?
- Is
Noneallowed in the lists, and should it be treated the same as an empty string?
What a strong answer covers
- Keeps two sets, emails and phones claimed by registered accounts. For each account it checks both and, only if both are free, registers it and adds its non-empty values to the sets.
- Does not add a duplicate's email or phone, which is what makes account 4 in the example register.
- Part 2 runs the normalization before both the check and the insert, so the sets hold only normalized values.
- O(n * L) time for strings of length L, and O(n * L) space for the sets.
- Tests: the example, empty and
Nonefields, one account blocked by email and another by phone, a duplicate followed by an account that reuses its values, lists of different lengths, and Part 2 cases such as" Ana@X.io "and"+1 (415) 555-0100".
Follow-ups
- Merge duplicates into one person instead of rejecting them, linking accounts that share any email or phone (union-find).
- Normalize further: Gmail dots and
+tags, and phone numbers with and without a country code. - Support deleting an account, which frees its email and phone.
- Run it at scale across many servers, where two sign-ups with the same email can arrive at once.
Where it's asked
- Airbnb · Coding · Last asked Apr 202645 min · Live coding, one or two rounds, from the same pool as the screen
What it tests
hash set · strings · simulation
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. New accounts get 5 credits: each one unlocks a question for good.
What the labs asked this week
A weekly email of what OpenAI, Anthropic and the other top AI labs asked engineers, round by round.
Sign in to submit your code; every attempt is kept here.
