[Java] Simple Solution | Bit Masking
Enumerate bitmask X from 0 to 2^N. If the ith bit of X is:\n 1, it means that person i is good.\n 0, it means that person i is bad.\n\nWe can ignore bad persons
Enumerate bitmask X from 0 to 2^N. If the ith bit of X is:\n* 1, it means that person i is good.\n* 0, it means that person i is bad.\n\nWe can ignore bad persons\' statements because they can be either true or false. But good persons\' statements must be all correct.\n\nTo test if this bitmask X is valid, we go through all the good persons\' statements and see if there is any contradiction.\n\n```\nclass Solution {\n    public int maximumGood(int[][] statements) {\n        int n = statements.length;\n        int res = 0;\n        \n        for(int i = 0; i < (1 << n); i++) {\n            if(isValidGuess(statements, i)) {\n                res = Math.max(res, countActiveBits(i));\n            }\n        }\n        \n        return res;\n    }\n    \n    private boolean isValidGuess(int[][] statements, int guess) {\n        int n = statements.length;\n        \n        for(int i = 0; i < n; i++) {\n            // if i-th person is a good person\n            if(isGuessedAsGood(guess, i, n)) {\n                // Since i is a good person, all the statements by i would be true\n                // So check if the statements given by i for other people\n                // and the guess made by us for those people are the same\n                // if not then the guess that we have made is not valid and return false\n                for(int j = 0; j < n; j++) {\n                    if(statements[i][j] != 2 &&\n                       statements[i][j] != (isGuessedAsGood(guess, j, n) ? 1 : 0)) {\n                        return false;\n                    }\n                }\n            }\n        }\n        \n        return true;\n    }\n    \n    private boolean isGuessedAsGood(int guess, int person, int total) {\n        // a person is a good person if the (n - 1 - i)th bit is 1\n        return (guess & (1 << (total - 1 - person))) > 0;\n    }\n    \n    private int countActiveBits(int num) {\n        int c = 0;\n        \n        while(num > 0) {\n            if((num & 1) > 0)\n                c++;\n            \n            num >>= 1;\n        }\n        \n        return c;\n    }\n    \n}\n```
['Bit Manipulation', 'Bitmask', 'Java']