Boolean Matrix Transformation Challenge

Given a 2-dimensional boolean matrix mat of size N x M, your task is to modify the matrix such that if any element is 1, set its entire row and column to 1. Specifically, if mat[i][j] = 1, then make all elements of the i-th row and j-th column equal to 1.

Note:

You are required to modify the input matrix in-place.

There is no need to print anything; the output handling is already managed.

Input:

The first line of input contains an integer 'T' representing the number of test cases.
The first line of each test case consists of two spaced integer values N and M indicating the matrix dimensions.
The following N lines for each test case contain M spaced integers (0 or 1) representing the matrix elements.

Output:

For every test case, display the modified matrix. Each test case output should be shown on a new line.

Example:

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

Constraints:

  • 1 <= T <= 10
  • 1 <= N, M <= 200
  • N and M represent the number of matrix rows and columns, respectively.
Be the first one to answer
Add answer anonymously...
Toppr 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