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 ith row and the jth 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.

Be the first one to answer
Add answer anonymously...
Deutsche Bank Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter