Account Deduplication

Asked at Airbnb

Reported by the problem's creator, not verified

A site keeps its sign-ups as a list of records in registration order. Each record is a map from attribute name to value, for example {"name": "john", "email": "[email protected]", "phone": "800 800 8800"}, and every record in a list has the same set of attribute names, whatever they are.

Go through the records in order. The first record to use a value for an attribute owns that value. A later record is a duplicate if it uses a value that is already owned for the same attribute; the same text under a different attribute does not count. Only records that are not duplicates register their values: a duplicate owns nothing, so it never makes a later record a duplicate.

Write find_duplicates(records). It returns the indices of the duplicate records in increasing order. Values are compared exactly, letter case included.

Examples

  1. Example 1

    Input: {"records":[{"name":"john","email":"[email protected]","phone":"800 800 8800"},{"name":"amy","email":"[email protected]","phone":"800 800 8800"},{"name":"johnny","email":"[email protected]","phone":"800 800 8888"}]}

    Output: [1,2]

    Explanation: Record 0 registers everything. Record 1 reuses the phone 800 800 8800, so it is a duplicate. Record 2 reuses the email [email protected] from record 0, so it is a duplicate too. The answer is [1, 2].

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.