Backtrack
Code
# Code
```java []
class Solution {
    int n;
    public int maximumGood(int[][] statements) {
        /**
        [2,1,2]
        [1,2,2]
        [2,0,2]
        
         */

        n = statements.length;
        return backtrack(statements, 0, new int[n], 0);
    }

    private int backtrack(int[][] statements, int currPerson, int[] isGood, int totalGoods) {
        if(currPerson == n) {
            if(isValidStatement(statements, isGood)) {
                return totalGoods;
            }
            return 0;
        }

        isGood[currPerson] = 1;
        int goodsWhenCurrGood = backtrack(statements, currPerson + 1, isGood, totalGoods + 1);
        isGood[currPerson] = 0;

        int goodsWhenCurrBad = backtrack(statements, currPerson + 1, isGood, totalGoods);

        return Math.max(goodsWhenCurrGood, goodsWhenCurrBad);
    }

    // check if current combination is correct
    private boolean isValidStatement(int[][] statements, int[] isGood) {
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                if(isGood[i] == 1 
                    && statements[i][j] != 2 
                    && statements[i][j] != isGood[j]) {
                    return false;
                }
            }
            
        }
        return true;
    }
}
```
['Java']