Given a Boolean Matrix, find k such that all elements in k'th row are 0 and k'th column are 1. Given a square boolean matrix mat[n][n], find k such that all elements in k'th row are 0 and all elements in k'th column are 1. The value of mat[k][k] can be anything (either 0 or 1). If no such k exists, return -1. Examples: Input: bool mat[n][n] = { {1, 0, 0, 0}, {1, 1, 1, 0}, {1, 1, 0, 0}, {1, 1, 1, 0}, }; Output: 0 All elements in 0'th row are 0 and all elements in 0'th column are 1. mat[0][0] is 1 (can be any value) Input: bool mat[n][n] = {{0, 1, 1, 0, 1}, {0, 0, 0, 0, 0}, {1, 1, 1, 0, 0}, {1, 1, 1, 1, 0}, {1, 1, 1, 1, 1}}; Output: 1 All elements in 1'st row are 0 and all elements in 1'st column are 1. mat[1][1] is 0 (can be any value) Input: bool mat[n][n] = {{0, 1, 1, 0, 1}, {0, 0, 0, 0, 0}, {1, 1, 1, 0, 0}, {1, 0, 1, 1, 0}, {1, 1, 1, 1, 1}}; Output: -1 There is no k such that k'th row elements are 0 and k'th column elements are 1.
Read full article from Given a Boolean Matrix, find k such that all elements in k'th row are 0 and k'th column are 1. - GeeksforGeeks
No comments:
Post a Comment