<p>Given the array <code>favoriteCompanies</code> where <code>favoriteCompanies[i]</code> is the list of favorites companies for the <code>ith</code> person (<strong>indexed from 0</strong>).</p>

<p><em>Return the indices of people whose list of favorite companies is not a <strong>subset</strong> of any other list of favorites companies</em>. You must return the indices in increasing order.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> favoriteCompanies = [[&quot;leetcode&quot;,&quot;google&quot;,&quot;facebook&quot;],[&quot;google&quot;,&quot;microsoft&quot;],[&quot;google&quot;,&quot;facebook&quot;],[&quot;google&quot;],[&quot;amazon&quot;]]
<strong>Output:</strong> [0,1,4] 
<strong>Explanation:</strong> 
Person with index=2 has favoriteCompanies[2]=[&quot;google&quot;,&quot;facebook&quot;] which is a subset of favoriteCompanies[0]=[&quot;leetcode&quot;,&quot;google&quot;,&quot;facebook&quot;] corresponding to the person with index 0. 
Person with index=3 has favoriteCompanies[3]=[&quot;google&quot;] which is a subset of favoriteCompanies[0]=[&quot;leetcode&quot;,&quot;google&quot;,&quot;facebook&quot;] and favoriteCompanies[1]=[&quot;google&quot;,&quot;microsoft&quot;]. 
Other lists of favorite companies are not a subset of another list, therefore, the answer is [0,1,4].
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> favoriteCompanies = [[&quot;leetcode&quot;,&quot;google&quot;,&quot;facebook&quot;],[&quot;leetcode&quot;,&quot;amazon&quot;],[&quot;facebook&quot;,&quot;google&quot;]]
<strong>Output:</strong> [0,1] 
<strong>Explanation:</strong> In this case favoriteCompanies[2]=[&quot;facebook&quot;,&quot;google&quot;] is a subset of favoriteCompanies[0]=[&quot;leetcode&quot;,&quot;google&quot;,&quot;facebook&quot;], therefore, the answer is [0,1].
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> favoriteCompanies = [[&quot;leetcode&quot;],[&quot;google&quot;],[&quot;facebook&quot;],[&quot;amazon&quot;]]
<strong>Output:</strong> [0,1,2,3]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= favoriteCompanies.length &lt;= 100</code></li>
	<li><code>1 &lt;= favoriteCompanies[i].length &lt;= 500</code></li>
	<li><code>1 &lt;= favoriteCompanies[i][j].length &lt;= 20</code></li>
	<li>All strings in <code>favoriteCompanies[i]</code> are <strong>distinct</strong>.</li>
	<li>All lists of favorite companies are <strong>distinct</strong>, that is, If we sort alphabetically each list then <code>favoriteCompanies[i] != favoriteCompanies[j].</code></li>
	<li>All strings consist of lowercase English letters only.</li>
</ul>

class Solution {
public:
    vector<int> peopleIndexes(vector<vector<string>>& favoriteCompanies) {
        unordered_map<string, int> s;
        int n = favoriteCompanies.size();
        int count = 0;
        for(int i=0; i<n; i++) {
            for(auto fc: favoriteCompanies[i]) {
                if(s.count(fc)>0) {
                    continue;
                }
                else {
                    s[fc] = count;
                    count++;
                }
            }
        }
        vector<bitset<50001>> arr(n, bitset<50001>(0));
        for(int i=0; i<n; i++) {
            //bitset<50001> bs = bitset<50001>(0);
            for(auto fc: favoriteCompanies[i]) {
                arr[i][s[fc]] = true;
            }
            //arr.push_back(bs);
        }

        vector<int> res;
        for(int i=0; i<n; i++) {
            bool flag = true;
            for(int j=0; j<n; j++) {
                if(i==j) continue;
                if((arr[i]&arr[j])==arr[i]) {
                    flag = false;
                    break;
                }
            }
            if(flag) res.push_back(i);
        }
        return res;
    }

    vector<int> peopleIndexes211(vector<vector<string>>& favoriteCompanies) {
        unordered_map<string, int> hm;
        int count = 0;
        for(int i=0; i<favoriteCompanies.size(); i++) {
            for(int j=0; j<favoriteCompanies[i].size(); j++) {
                //cout<<favoriteCompanies[i][j]<<" ";
                if(hm.find(favoriteCompanies[i][j])==hm.end()) {
                    hm[favoriteCompanies[i][j]] = count;
                    count++;
                }
            }
        }
        cout<<count<<endl;
        int n = favoriteCompanies.size();
        vector<vector<int>> arr(n, vector<int>(count, false));
        // map to binary rep
        for(int i=0; i<favoriteCompanies.size(); i++) {
            for(int j=0; j<favoriteCompanies[i].size(); j++) {
                arr[i][hm[favoriteCompanies[i][j]]] = true;
            }
        }

        vector<int> res(n, true);
        vector<int> ans;
        for(int i=0; i<n; i++) {
            for(int j=i+1; j<n; j++) {
                int sumv = 0;
                for(int c = 0; c<count; c++) {
                    sumv += (arr[i][c]&arr[j][c]);
                }
                if(sumv==favoriteCompanies[i].size()) {
                    res[i] = false;
                }
                if(sumv==favoriteCompanies[j].size()) {
                    res[j] = false;
                }
            }

            if(res[i]) {
                ans.push_back(i);
            }
        }

        return ans;
    }
};
101400