New update is available. Click here to update.
Close
Topic list
Set Matrix Zeros
EASY
30 mins
Matrices (2D Arrays)
Topics (Covered in this problem)
Problem solved
Skill meter
Matrices (2D Arrays)
-
-
Other topics
Problem solved
Skill meter
Strings
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Set Matrix Zeros

Contributed by
Ashwani
Easy
0/40
Avg time to solve 30 mins
Success Rate 65 %
Share

## Problem Statement

#### For Example:

``````If the given grid is this:
[7, 19, 3]
[4, 21, 0]

Then the modified grid will be:
[7, 19, 0]
[0, 0,  0]
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1 :
``````2
2 3
7 19 3
4 21 0
3 3
1 2 3
4 0 6
7 8 9
``````
##### Sample Output 1 :
``````7 19 0
0 0 0
1 0 3
0 0 0
7 0 9
``````
##### Explanation For Sample Input 1 :
``````For First Case - Similar to the example explained above.

For Second Case -
Only the cell (2,2) has zero. So all the elements of the second row and second column are changed to zeros.
``````
##### Sample Input 2 :
``````2
4 2
1 0
2 7
3 0
4 8
3 3
0 2 3
1 0 3
1 2 0
``````
##### Sample Output 2 :
``````0 0
2 0
0 0
4 0
0 0 0
0 0 0
0 0 0
``````
Auto
Console