1452. People Whose List of Favorite Companies Is Not a Subset of Another List
Posted on
Description
Submission
class Solution {
public:
vector<int> peopleIndexes(vector<vector<string>>& favoriteCompanies) {
int n = favoriteCompanies.size();
unordered_map<string, bitset<100>> c2p;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < favoriteCompanies[i].size(); ++j) {
c2p[favoriteCompanies[i][j]][i] = 1;
}
}
vector<int> rets;
// for each person
for(int i = 0; i < n; ++i) {
bitset<100> bs;
bs.set();
// for all the companies for the person
// find the union set
for(string c: favoriteCompanies[i]) {
bs &= c2p[c];
}
// if there's only 1 bit left, i.e. only the person
if(bs.count() == 1) {
rets.push_back(i);
}
}
return rets;
}
};