Backtracking simple & clean
Intuition\nUse backtrack to take guess one by one, at each step, find if there is any contradiction.\n\n# Code\n\nclass Solution:\n    def maximumGood(self, sta
# Intuition\nUse backtrack to take guess one by one, at each step, find if there is any contradiction.\n\n# Code\n```\nclass Solution:\n    def maximumGood(self, statements: List[List[int]]) -> int:\n        n = len(statements)\n        ans = 0\n        deduction = [2] * n  # same as statements, 0 if bad, 1 if good, 2 if we haven\'t assumed yet \n\n        def backtracking(i, deduction):\n            nonlocal ans\n\n            # if we complete the deduction, than we have a valid answer, calculate the # of good\n            if deduction[-1] != 2: \n                ans = max(ans, sum([_ == 1 for _ in deduction]))\n                return\n\n            # assume i is good\n            deduction[i] = 1\n            for j in range(n):\n                if j != i:\n                    if deduction[j] != 2 and statements[i][j] != 2:\n                        # if what i says to j does not match what we assume j previously\n                        if deduction[j] != statements[i][j]:\n                            break\n                    # if j is good but j says i is bad\n                    if deduction[j] == 1 and statements[j][i] == 0:\n                        break\n            else:\n                # no contradiction found, take the next guess\n                backtracking(i+1, deduction)\n            \n            # assume i is bad\n            deduction[i] = 0\n            for j in range(n):\n                if j != i:\n                    # if j is good and j says i is good\n                    if deduction[j] == 1 and statements[j][i] == 1:\n                        break\n            else:\n                # no contradiction found, take the next guess\n                backtracking(i+1, deduction)\n\n            # restore the status\n            deduction[i] = 2\n                \n        backtracking(0, deduction)\n        return ans\n                \n            \n\n```
['Python3']