People Whose List of Favorite Companies Is Not a Subset of Another List - Problem
Given the array favoriteCompanies where favoriteCompanies[i] is the list of favorite 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 favorite companies. You must return the indices in increasing order.
A subset means that all elements of list A appear in list B, but B can have additional elements.
Input & Output
Example 1 — Basic Case
$
Input:
favoriteCompanies = [["leetcode","google","facebook"],["leetcode","microsoft"],["google","microsoft"]]
›
Output:
[0,1,2]
💡 Note:
Person 0 ["leetcode","google","facebook"] is not a subset of any other list. Person 1 ["leetcode","microsoft"] is not a subset of any other list (person 0 is missing "microsoft", person 2 is missing "leetcode"). Person 2 ["google","microsoft"] is not a subset of any other list. So all indices [0,1,2] are returned.
Example 2 — No Subsets
$
Input:
favoriteCompanies = [["leetcode","google","facebook"],["google","microsoft"],["facebook","linkedin"]]
›
Output:
[0,1,2]
💡 Note:
No person's list is a complete subset of another person's list, so all indices are returned
Example 3 — Multiple Subsets
$
Input:
favoriteCompanies = [["a","b"],["a"],["b"],["a","b","c"]]
›
Output:
[3]
💡 Note:
Person 0 ["a","b"] ⊆ Person 3 ["a","b","c"], Person 1 ["a"] ⊆ multiple others, Person 2 ["b"] ⊆ multiple others. Only Person 3 is not a subset of anyone.
Constraints
- 1 ≤ favoriteCompanies.length ≤ 100
- 1 ≤ favoriteCompanies[i].length ≤ 500
- 1 ≤ favoriteCompanies[i][j].length ≤ 20
- All strings in favoriteCompanies[i] are distinct
- All the strings of favoriteCompanies are distinct
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code