For a two-dimensional array of equal dimensions (ie nxn) containing only 0 and 1, how can I find (ignoring the matrix [i] [i]) the i-th row that has all 0 and the i-th column that has all 1. If such a self does not exist, then return -1.
matrix [i] [i] can have anything.
Expected time complexity: O (n)
for example
for a given 4 × 4 matrix
1 1 0 0
0 1 0 0
1 1 0 1
0 1 0 0
the answer is 1 (i is based on zero), because the 2nd row has all 0, and the second column has all 1 (the value in [1, 1] is ignored).
source
share