Account Deduplication
AirbnbEasy
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.
Part 1: Flag the duplicate records
For example, with the three records {"name": "john", "email": "[email protected]", "phone": "800 800 8800"}, {"name": "amy", "email": "[email protected]", "phone": "800 800 8800"} and {"name": "johnny", "email": "[email protected]", "phone": "800 800 8888"}, record 1 repeats a phone number and record 2 repeats an email, so the result is [1, 2].
- Example 1
- 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]
Why: 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].
Constraints
0 <= len(records) <= 10^4- Every record has the same attribute names.
1 <= len(records[i]) <= 20len(value) <= 50for every value