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.

AnswerBot
4mo

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

Help your peers!
Select
Add answer anonymously...

Deutsche Bank Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Query and Matrix Problem Statement You are given a binary matrix with 'M' rows a...read more
A Software Developer Intern was asked Q. Jump Game Problem Statement In this problem, you are given an array ARR consisti...read more
A Software Developer Intern was asked Q. Dijkstra's Shortest Path Problem Given an undirected graph with ‘V’ vertices (la...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Query and Matrix Problem Statement You are given a binary matrix with 'M' rows a...read more
A Software Developer Intern was asked Q2. Jump Game Problem Statement In this problem, you are given an array ARR consisti...read more
A Software Developer Intern was asked Q3. Dijkstra's Shortest Path Problem Given an undirected graph with ‘V’ vertices (la...read more
Deutsche Bank Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits