Problem Description
Robin purchase an integer matrix A of size N x M
.
He wants to make the matrix Diagonally powerful Matrix, but he can only use the below operation:
Matrix is called Diagonally powerful matrix if all diagonals starting from Top or Left
and ending at Bottom or Right
is Powerful.
A diagonal is powerful if bitwise AND of the elements in the diagonal is greater than 1.
Find and return the minimum number of operations required to convert the matrix into Diagonally powerful Matrix.
1 <= N x M <= 104
1 <= A[i][j] <= 107
First and only argument is a 2D array A.
Return an integer denoting the minimum number of operations required to convert the matrix into Diagonally powerful Matrix.
Input 1:
A = [ [2, 2, 1] [10, 4, 1] [11, 3, 2] ]
Input 2:
A = [ [1] [5] ]
Output 1:
3
Output 2:
1
Explanation 1:
Three operations are required: Select all 1's and multiply by 2 and select 4 and divide it by 2.
Explanation 2:
Select 1 and multiply by 2, since we need AND greater than 1.
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a question? Checkout Sample Codes for more details.