Matrix Bit Flipping Problem
In this task, you're provided with a binary square matrix of size 'N * N' named MAT
. The task requires you to perform row and column flips whenever a zero (0) is encountered in the matrix. Specifically, for any position (i, j)
where MAT[i][j]
is 0, flip all 1s located in the i
th row and the j
th column of the matrix.
Your Objective:
Return the total count of these flipping operations across the entire matrix.
Example:
Input:
T = 1
N = 3
MAT = [[0, 1, 1],
[1, 1, 1],
[1, 0, 1]]
Output:
6
Explanation:
Considering the matrix above, when we encounter a 0, the 1s in that row or column are flipped, yielding a total of 6 flips as shown in the images.
Constraints:
1 ≤ T ≤ 5
0 ≤ N ≤ 100
MAT[i][j]
is either 0 or 1.- For each zero, flips are only counted in its initial state, not the state after any flips.
Note:
You only need to implement the solution function, as printing the output is handled elsewhere.
Count the total number of flips required in a binary matrix when encountering zeros.
Iterate through the matrix and whenever a zero is encountered, flip all 1s in the corresponding row and column.
Keep ...read more
Top Deutsche Bank Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Top HR questions asked in Deutsche Bank Software Developer Intern
Reviews
Interviews
Salaries
Users/Month