Well explained java solution, DFS with Backtracking, beat 99.9%
\nclass Solution {\n    public int maximumGood(int[][] statements) {  \n        int[] result = { 0 };      \n        maximumGood(statements, new boolean[stateme
```\nclass Solution {\n    public int maximumGood(int[][] statements) {  \n        int[] result = { 0 };      \n        maximumGood(statements, new boolean[statements.length], 0, 0, result);\n        return result[0];\n    }\n    \n    /*\n        This function uses backtracking to do the DFS. We are basically constructing all possible scenarios and verifying them.\n\n        statements (int[][]): This is the input statements.\n        goodPeople (boolean[]): This array tells who are good and bad in the group.\n        currentPerson (int): This is the current person that we are verifying.\n        currentGoodPeople (int): This is the number of the good people identified so far.\n        result (int[]): This array holds the result, the total number of good people.\n    */\n    private void maximumGood(int[][] statements, boolean[] goodPeople, int currentPerson, int currentGoodPeople, int[] result) {\n        if (currentPerson == goodPeople.length) {\n            result[0] = Math.max(result[0], currentGoodPeople);\n            return;\n        }\n        \n        // Now we are going to use backtracking to do DFS.\n\n        // Scenario 1: Assume the current person is good and verify it.\n        goodPeople[currentPerson] = true;\n        // Prune the tree if the sum of unverified people (goodPeople.length - currentPerson) and verifyied good people (currentGoodPeople) is less than the result.\n        if (goodPeople.length - currentPerson + currentGoodPeople < result[0]) {\n            return;\n        }\n        if (isValid(statements, goodPeople, currentPerson)) {\n            maximumGood(statements, goodPeople, currentPerson + 1, currentGoodPeople + 1, result);\n        }\n\n        // Scenario 2: Assume the current person is bad and verify it.\n        goodPeople[currentPerson] = false;      \n        // Prune the tree for the same reason mentioned earlier.  \n        if (goodPeople.length - currentPerson - 1 + currentGoodPeople < result[0]) {\n            return;\n        }\n        if (isValid(statements, goodPeople, currentPerson)) {\n            maximumGood(statements, goodPeople, currentPerson + 1, currentGoodPeople, result);\n        }\n        \n        return;\n    }\n    \n    private boolean isValid(int[][] statements, boolean[] goodPeople, int currentPerson) {\n        // To verify if the current assumption of good/bad people is correct, we need to do 2 things.\n        // 1. We need to verify the statements from all processed good people. What they said about the current person should be correct.\n        for (int i = 0; i < currentPerson; ++i) {\n            if (goodPeople[i]) {\n                if (goodPeople[currentPerson] && statements[i][currentPerson] == 0) {\n                    return false;\n                }\n                if (!goodPeople[currentPerson] && statements[i][currentPerson] == 1) {\n                    return false;\n                }\n            }\n        }\n        \n        // 2. We need to verify the statement from the current person if he is good. What he said about other people should be correct.\n        if (goodPeople[currentPerson]) {\n            for (int i = 0; i < currentPerson; ++i) {\n                if (goodPeople[i] && statements[currentPerson][i] == 0) return false;\n                if (!goodPeople[i] && statements[currentPerson][i] == 1) return false;\n            }\n        }\n\n        return true;\n    }\n}\n```
['Backtracking', 'Depth-First Search', 'Java']