Reset Matrix Problem Statement
Given a 2D array ARR
with 'N' rows and 'M' columns, where each element is either 0 or 1, your task is to transform this matrix into a 'Good' matrix. A 'Good' matrix is one in which for every 0 found in the matrix, all elements in its row and column are set to 0.
Example:
Input:
ARR = [[1, 0, 1], [1, 1, 1], [1, 1, 1]]
Output:
[[0, 0, 0], [1, 0, 1], [1, 0, 1]]
Explanation:
Since ARR[0][1]
is 0, all elements in the 0-th row and 1-th column are set to 0.
Constraints:
1 ≤ T ≤ 20
1 ≤ N ≤ 300
1 ≤ M ≤ 300
ARR[i][j]
can only be 0 or 1
Note: No need to print the matrix; update the input matrix as per the requirements.
AnswerBot
21d
Transform a 2D array into a 'Good' matrix by setting rows and columns to 0 if a 0 is found.
Iterate through the matrix to find 0s
For each 0 found, set all elements in its row and column to 0
Update the ...read more
Help your peers!
Add answer anonymously...
Top Infosys System Engineer Specialist interview questions & answers
Top HR questions asked in Infosys System Engineer Specialist
Stay ahead in your career. Get AmbitionBox app
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
Get AmbitionBox app