FastPrepThree-Speaker Truth Consistency

Three-Speaker Truth Consistency

Susquehanna International Group (SIG) logoSusquehanna International Group (SIG)● EasyFULLTIMEOA
Learn

Problem statement

Three speakers A, B, and C each make one statement. For this exercise, assume every option assigns a Boolean truth value to each speaker's statement.

An option is an integer mask from 0 through 7. Bit 0 gives A's assigned truth value, bit 1 gives B's, and bit 2 gives C's. A set bit means true; an unset bit means false.

The 3 x 8 matrix statements supplies the truth table of the statements: statements[s][mask] is the truth value of speaker s's statement in the world represented by mask, with speakers ordered A, B, C. These supplied tables define the statements; you do not need to parse natural language.

An option is consistent when both conditions hold:

  • For every speaker s, the supplied statement truth statements[s][mask] equals bit s of mask.
  • Not all three statements are true, so mask = 7 is excluded. All three statements may be false.

Given statements and the ordered array options, return the zero-based index of the first consistent option. Return -1 if no offered option is consistent. Duplicate options are allowed and keep their original positions.

Function

firstConsistentOption(statements: int[][], options: int[]) → int

Examples

Example 1

statements = [[0,0,1,1,0,0,1,1],[0,1,0,1,0,1,0,1],[0,0,0,0,0,0,0,0]]options = [7,2,3,0]return = 2

The supplied tables require A and B to have the same truth value, while C is false. Masks 3 and 0 are consistent. Mask 3 appears first in the offered list, at index 2.

Example 2

statements = [[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1]]options = [7,6,3]return = -1

Only mask 7 agrees with the three constant-true statements. It is excluded because all three truth bits are 1, so no offered option qualifies.

Example 3

statements = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]]options = [0]return = 0

Mask 0 makes all three statements false. This satisfies the requirement that not all statements are true, so the option at index 0 qualifies.

Constraints

  • statements.length = 3 and every row has length 8.
  • Every table entry is 0 or 1.
  • 0 <= options.length <= 1000.
  • 0 <= options[i] <= 7.

More Susquehanna International Group (SIG) problems

See Susquehanna International Group (SIG) hiring insights
public int firstConsistentOption(int[][] statements, int[] options) {
    // write your code here
}
statements[[0,0,1,1,0,0,1,1],[0,1,0,1,0,1,0,1],[0,0,0,0,0,0,0,0]]
options[7,2,3,0]
expected2
Checking account…