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.

Be the first one to answer
Add answer anonymously...
Compass Group Support Services Software Engineer 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