Bit masking | C++ | Do not sleep during contest :(
I slept after solving 1st three problem and wake up with 1.2k submission on this shitty brute force problem xD.\nP.S. Never fall asleep in morning contest.\n\nc
I slept after solving 1st three problem and wake up with 1.2k submission on this shitty brute force problem xD.\nP.S. Never fall asleep in morning contest.\n```\nclass Solution {\npublic:\n    int maximumGood(vector<vector<int>>& A) {\n        int n = A.size(), ans = 0;\n        for(int mask = 0; mask < (1 << n); mask++){\n            // mask is our assumption : 101 means person 0, 2 are good and person 1 is bad.\n            bool valid = true;\n            for(int i = 0; i < n; i++){\n                // if person at ith bit is good\n                if(mask & (1 << i)){\n                    for(int j = 0; j < n; j++){\n                        // check for contradiction\n                        if(A[i][j] != 2 && A[i][j] != bool(mask & (1 << j))){\n                            valid = false;\n                            break;\n                        }\n                    }\n                }\n            }\n            if(valid) ans = max(ans, __builtin_popcount(mask));\n        }\n        return ans;\n    }\n};\n```
['Bitmask']