#1452
Medium Algorithms People whose list of favorite companies is not a subset of another list
Array Hash Table String
60.5% acceptance
Feb 25, 2026
382
230
Given a list of lists of companies, find people whose list of favorite companies is not a subset of any other list of favorite companies.
Return the indices of these people in increasing order.
Solution
Rust
Time O(n)
Space O(1)
use std::collections::HashSet;
impl Solution {
pub fn people_indexes(favorite_companies: Vec<Vec<String>>) -> Vec<i32> {
let sets: Vec<HashSet<&str>> = favorite_companies.iter()
.map(|v| v.iter().map(|s| s.as_str()).collect())
.collect();
(0..sets.len())
.filter(|&i| !sets.iter().enumerate().any(|(j, sj)| j != i && sets[i].is_subset(sj)))
.map(|i| i as i32)
.collect()
}
}