1452. People Whose List of Favorite Companies Is Not a Subset of Another List LeetCode Solution
In this guide, you will get 1452. People Whose List of Favorite Companies Is Not a Subset of Another List LeetCode Solution with the best time and space complexity. The solution to People Whose List of Favorite Companies Is Not a Subset of Another List problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.
Table of Contents
- Problem Statement
- Complexity Analysis
- People Whose List of Favorite Companies Is Not a Subset of Another List solution in C++
- People Whose List of Favorite Companies Is Not a Subset of Another List solution in Java
- People Whose List of Favorite Companies Is Not a Subset of Another List solution in Python
- Additional Resources

Problem Statement of People Whose List of Favorite Companies Is Not a Subset of Another List
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.
Example 1:
Input: favoriteCompanies = [[“leetcode”,”google”,”facebook”],[“google”,”microsoft”],[“google”,”facebook”],[“google”],[“amazon”]]
Output: [0,1,4]
Explanation:
Person with index=2 has favoriteCompanies[2]=[“google”,”facebook”] which is a subset of favoriteCompanies[0]=[“leetcode”,”google”,”facebook”] corresponding to the person with index 0.
Person with index=3 has favoriteCompanies[3]=[“google”] which is a subset of favoriteCompanies[0]=[“leetcode”,”google”,”facebook”] and favoriteCompanies[1]=[“google”,”microsoft”].
Other lists of favorite companies are not a subset of another list, therefore, the answer is [0,1,4].
Example 2:
Input: favoriteCompanies = [[“leetcode”,”google”,”facebook”],[“leetcode”,”amazon”],[“facebook”,”google”]]
Output: [0,1]
Explanation: In this case favoriteCompanies[2]=[“facebook”,”google”] is a subset of favoriteCompanies[0]=[“leetcode”,”google”,”facebook”], therefore, the answer is [0,1].
Example 3:
Input: favoriteCompanies = [[“leetcode”],[“google”],[“facebook”],[“amazon”]]
Output: [0,1,2,3]
Constraints:
1 <= favoriteCompanies.length <= 100
1 <= favoriteCompanies[i].length <= 500
1 <= favoriteCompanies[i][j].length <= 20
All strings in favoriteCompanies[i] are distinct.
All lists of favorite companies are distinct, that is, If we sort alphabetically each list then favoriteCompanies[i] != favoriteCompanies[j].
All strings consist of lowercase English letters only.
Complexity Analysis
- Time Complexity:
- Space Complexity:
1452. People Whose List of Favorite Companies Is Not a Subset of Another List LeetCode Solution in C++
class Solution:
def peopleIndexes(self, favoriteCompanies: list[list[str]]) -> list[int]:
ans = []
n = len(favoriteCompanies)
companies = [set(comp) for comp in favoriteCompanies]
for i in range(n):
find = False
for j in range(n):
if i == j:
continue
if companies[i].issubset(companies[j]):
find = True
break
if not find:
ans.append(i)
return ans
/* code provided by PROGIEZ */
1452. People Whose List of Favorite Companies Is Not a Subset of Another List LeetCode Solution in Java
N/A
// code provided by PROGIEZ
1452. People Whose List of Favorite Companies Is Not a Subset of Another List LeetCode Solution in Python
N/A
# code by PROGIEZ
Additional Resources
- Explore all LeetCode problem solutions at Progiez here
- Explore all problems on LeetCode website here
Happy Coding! Keep following PROGIEZ for more updates and solutions.