![]() |
VOOZH | about |
Given a binary matrix B[][] of size N*M, the task is to find a matrix A[][] of the same size such that B[i][j] is the bitwise AND of all the elements in ith row and jth column of A[][].
Examples:
Input: B[][] = { {1, 0, 1}, {0, 0, 0} }
Output: { {1, 1, 1}, {1, 0, 1} }
Explanation:
1 1 1 ? 1 0 1
1 0 1 0 0 0Input: B[][] = { {0, 0}, {1, 1} }
Output: -1
Approach: Follow the below idea to solve the problem:
If any cell contains 1 means that in every cell of that row and column there should not be any 0 because if it is it will dominate 1.
Follow the steps to solve this problem:
Below is the implementation of the above approach.
1 1 1 1 0 1
Time Complexity: O(N*M)
Auxiliary Space: O(N*M)