- categories: Code, Interview Question, leetcode, Medium
- source: https://leetcode.com/problems/people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list
- topics: Hash Table
Given the array favoriteCompanies
where favoriteCompanies[i]
is the list of favorites companies for the ith
person (indexed from 0).
Return the indices of people whose list of favorite companies is not a subset of any other list of favorites companies. You must return the indices in increasing order.
class Solution(object):
def peopleIndexes(self, favoriteCompanies):
"""
:type favoriteCompanies: List[List[str]]
:rtype: List[int]
"""
hashes = [set(person) for person in favoriteCompanies]
ans = list(range(len(favoriteCompanies)))
for i, p1 in enumerate(hashes):
for p2 in hashes:
if p1 == p2 or len(p2) < len(p1):
continue
if not p1 < p2:
continue
else:
ans.remove(i)
break
return ans