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 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.
Reconstructed from the reported question; details may differ from what interviewers ask.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
