Skip to content

Practice Maximum Good People Based on Statements

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2151
LeetCode Problem

Maximum Good People Based on Statements

Problem Statement

A good person always tells the truth; a bad person may either lie or tell the truth. In statements[i][j], 0 means person i says j is bad, 1 means i says j is good, and 2 means no statement is made. Everyone’s self-entry is 2. Find an assignment of good and bad people consistent with every statement made by good people, and return the maximum possible number of good people. Statements by bad people impose no truth requirement.

Source: Maximum Good People Based on Statements on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
statements = [[2,1,2],[1,2,2],[2,0,2]]
Output
2

# Example 2

Input
statements = [[2,0],[0,2]]
Output
1

Constraints

n == statements.length == statements[i].length
2 <= n <= 15
statements[i][j] is either 0, 1, or 2.
statements[i][i] == 2

Related LeetCode Problems

Practice more problems similar to Maximum Good People Based on Statements.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.