[
hash table
array
]
BinarySearch 0964 Unique People in Contact List
Problem statement
https://binarysearch.com/problems/Unique-People-in-Contact-List/
Solution
Just do what is asked: keep set of already seen emails.
Complexity
It is O(n)
for time and space, where n
is total length of all contacts.
Code
class Solution:
def solve(self, contacts):
seen, ans = set(), 0
for row in contacts:
if not set(row) & seen: ans += 1
seen |= set(row)
return ans