Make Zeroes
Submissions: 734   Accuracy:


  Difficulty: Easy   Marks: 2

Given a Matrix A[][] of N x M elements. Your task is to make Zeroes, that means in whole Matrix when you find a zero, convert its upper, lower, left, and right value to zero and make that element the sum of the upper, lower, left and right value. Do the following tasks according to the initial Matrix.
For Example:
Output Array should look like:
The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines.
First line of each test case consist of two space separated integers N and M, denoting the number of element in a row and column respectively.
Second line of each test case consists of N*M space separated integers denoting the elements in the matrix in row major order.

It should be single line output, Print the respective output in the respective line.



4 4
1 2 3 4 5 6 0 7 8 9 4 6 8 4 5 2

1 2 0 4 5 0 20 0 8 9 0 6 8 4 5 2

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Saksham Raj Seth
Author: saksham seth

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use, generate link and share the link here.

to report an issue on this page.