Maximum Good People Based on Statements
There are two types of persons:
- The good person: The person who always tells the truth.
- The bad person: The person who might tell the truth and might lie.
You are given a 0-indexed 2D integer array statements of size n x n that represents the statements made by n people about each other. More specifically, statements[i][j] could be one of the following:
0represents a statement made by personithat personjis a bad person.1represents a statement made by personithat personjis a good person.2represents that no statement is made by personiabout personj.
Additionally, no person ever makes a statement about themselves. Formally, statements[i][i] = 2 for all 0 <= i < n.
Return the maximum number of people who can be good based on the statements made by the n people.
Example 1
Input
statements = [[2,1,2],[1,2,2],[2,0,2]]Output
2At most 2 persons can be good in the best case.
Example 2
Input
statements = [[2,0],[0,2]]Output
1At most one person can be good in the best case.
Constraints
- n == statements.length == statements[i].length
- 2 <= n <= 15
- statements[i][j] is either 0, 1, or 2.
- statements[i][i] == 2