Sum Of Zeroes Coverage Calculation

You are provided with a binary matrix containing dimensions 'N * M', comprised only of 0s and 1s. Your task is to compute the aggregated sum of coverages for all the zeros in the matrix.

The coverage for any specific zero is defined as the count of 1s present in its immediate neighboring cells (specifically the top, bottom, left, and right adjacent positions).

Input:

The first line contains a single integer 'T' which indicates the number of test cases. 
For each test case, the first line contains two integers 'N' and 'M', representing the matrix dimensions.
The following N lines contain M space-separated integers of the matrix, with each integer being either 0 or 1.

Output:

For every test case, output the total coverage sum of all 0s in the matrix.

Example:

Input:
2
3 3
0 1 0
1 0 1
0 1 0
2 2
1 0
0 1

Output:
8
4

Constraints:

  • 1 <= T <= 10
  • 1 <= N, M <= 103

Note: No need to print the results as this functionality is handled internally. Focus on implementing the function to return the desired output.

AnswerBot
2mo

Calculate the total coverage of zeros in a binary matrix based on adjacent ones in a defined neighborhood.

  • Matrix Traversal: Iterate through each cell in the N x M matrix to identify zeros.

  • Neighbor Cou...read more

greatakamai
1mo
currently not working
The 3x3 matrix answer should be 12, you didn't count the (2,0) and (2,2) cells
Help your peers!
Select
Add answer anonymously...

Top Software Engineer Interview Questions Asked at Compass Group Support Services

Q. Nth Fibonacci Number Problem Statement Calculate the Nth term in the Fibonacci s...read more
Q. Word Occurrence Counting Given a string 'S' of words, the goal is to determine t...read more
Q. Kth Smallest Element Problem Statement You are provided with an array of integer...read more
Software Engineer 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