Problem Statement
You are given a
We say that a table is nice if there are two sequences x, y of zeroes and ones such that for each valid pair of indices i, j we have t[i][j] = x[i] xor y[j].
Some technical remarks:
- The number of elements in x should be equal to the number of rows of the table, i.e., the number of elements in t.
- The number of elements in y should be equal to the number of columns of the table, i.e., the length of each string in t.
- The operation xor (exclusive or) is defined as follows: 0 xor 0 = 0, 1 xor 1 = 0, 0 xor 1 = 1, and 1 xor 0 = 1.
Verify whether the given table is nice. Return "Nice" if it is nice and "Not nice" otherwise. Note that the return value is case-sensitive.
Definition
- Class:
- NiceTable
- Method:
- isNice
- Parameters:
- String[]
- Returns:
- String
- Method signature:
- String isNice(String[] t)
- (be sure your method is public)
Constraints
- t will contain between 1 and 5 elements, inclusive.
- Each element of t will contain between 1 and 5 characters, inclusive.
- All elements of t will contain the same number of characters.
- Each element of t will consist only of characters '0' and '1'.
Examples
{"01", "10"}
Returns: "Nice"
One valid choice is to choose x = y = {1, 0}.
{"01", "11"}
Returns: "Not nice"
Assume that t is nice. The sequences x and y have to satisfy the following constraints: x[0] xor y[0] = 0 x[0] xor y[1] = 1 x[1] xor y[0] = 1 x[1] xor y[1] = 1 From the first constraint we see that x[0] = y[0]. From the second and the third constraint we can then derive that we must also have x[1] = y[1]. But then the fourth constraint is not satisfied, which is a contradiction. Therefore, this t is not nice.
{"010", "101", "010"}
Returns: "Nice"
Here one of possible x and y are x = y = "101".
{"01", "01"}
Returns: "Nice"
{"1"}
Returns: "Nice"
{"111", "000", "111"}
Returns: "Nice"
{"001", "000", "001"}
Returns: "Not nice"
{"01100", "01100", "01100", "01100", "01100"}
Returns: "Nice"
{"0", "1", "0", "1", "0"}
Returns: "Nice"
{"11000"}
Returns: "Nice"
{"0010", "1101", "0010"}
Returns: "Nice"
{"00111", "00111"}
Returns: "Nice"
{"110", "110", "110", "001", "110"}
Returns: "Nice"
{"00111", "00111", "00111", "00111", "00111"}
Returns: "Nice"
{"0100", "1011", "0100"}
Returns: "Nice"
Here, one valid choice is x = {1, 0, 1} and y = {1, 0, 1, 1}.
{"01011", "01011", "10100", "01011", "10000"}
Returns: "Not nice"
{"10111", "10110", "10111", "00000", "10111"}
Returns: "Not nice"
{"11", "10", "11", "11", "11"}
Returns: "Not nice"
{"1110", "0001", "0001"}
Returns: "Nice"
{"10010", "01101", "11101", "01010", "11101"}
Returns: "Not nice"
{"1001", "1000", "1000"}
Returns: "Not nice"
{"11111", "11111", "11111", "11111", "11111"}
Returns: "Nice"
{"10101", "01010", "10101", "01010", "10101"}
Returns: "Nice"
{"11100", "11100", "11100", "00011", "00011"}
Returns: "Nice"
{"00000", "00000", "00000", "00000", "00000"}
Returns: "Nice"
{"111", "111"}
Returns: "Nice"
{"0100", "1011", "0100" }
Returns: "Nice"
{"01", "10" }
Returns: "Nice"
{"0100", "1011" }
Returns: "Nice"
{"00", "00" }
Returns: "Nice"
{"01", "11" }
Returns: "Not nice"
{"110", "011" }
Returns: "Not nice"
{"0" }
Returns: "Nice"
{"000", "000", "000" }
Returns: "Nice"
{"1" }
Returns: "Nice"
{"10101", "01010", "11111", "00011", "10111" }
Returns: "Not nice"
{"1", "1" }
Returns: "Nice"
{"01", "01" }
Returns: "Nice"
{"10", "01" }
Returns: "Nice"
{"001", "000" }
Returns: "Not nice"
{"111", "111", "111" }
Returns: "Nice"
{"11", "11" }
Returns: "Nice"
{"100", "100" }
Returns: "Nice"