C++ O(2^n * n^2) Power Set With Comments.
\nclass Solution {\npublic:\n    int maximumGood(vector<vector<int>>& statements) {\n        int n = statements.size();\n        int ans = 0;\n        // Checki
```\nclass Solution {\npublic:\n    int maximumGood(vector<vector<int>>& statements) {\n        int n = statements.size();\n        int ans = 0;\n        // Checking for each permutation.\n        // every number from 1 to 2^n -1 will represent a permutation.\n        // Each permutation can be valid answer but we will choose the one which has\n        // maximum number of true person, that is which number has maximum number of set_bits in it.\n        for(int i=1;i<(1<<n);i++) {\n            bool flag = true;\n            // checking each bit of each number.\n            // there will be n bits of each number.\n            // if jth bit of ith number is true, that means that in our ith permutation jth person is good.\n            // if jth bit of ith number is false, that means that in our ith permutation jth person is bad.\n            for(int j=0;j<n;j++) {\n                // if the jth bit of ith number is zero that means\n                // the jth person is a bad person, and we don\'t need to check for his \n                // statements as he can be lying.\n                if(!(i&(1<<j))) {\n                    continue;\n                }\n                // jth bit of ith number is one that means \n                // the jth person is a good person, therefore we will be checking further.\n                for(int k=0;k<n;k++) {\n                    // if jth person told that kth person is good, but kth bit in \n                    // i is 0, i.e in our permuatation kth person is bad, then this permutation is wrong.\n                    // as jth person is can\'t lie, because jth person is a good person.\n                    if(statements[j][k] == 1 && (!(i & (1<<k)))) {\n                        flag = false;\n                        break;\n                    }\n                    // if the jth person told that kth person is a bad, but kth bit in i is 1\n                    // i.e. in our permuation kth person is good, then it will also be contradictory.\n                    if(statements[j][k] == 0 && (i & (1<<k))) {\n                        flag = false;\n                        break;\n                    }\n                    // if our current permuation is invalid then break.\n                    // and check for next permutation.\n                    if(!flag) {\n                        break;\n                    }\n                }\n            }\n            if(flag) {\n                ans = max(ans,__builtin_popcount(i));\n            }\n        }\n        return ans;\n    }\n};\n```
['Bitmask']