Grokking 75: Top Coding Interview Questions
Ask Author
Back to course home

0% completed

Solution: Set Matrix Zeroes
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

Given a 2D grid of numbers called matrix, if any number in the grid is 0, set the entire row and column containing that zero to zeros.

The grid should be modified in place without using any extra grid.

Examples

Example 1:

  • Input: matrix =
[[2, 3, 4], 
 [5, 0, 6], 
 [7, 8, 9]]
  • Expected Output:
[[2, 0, 4], 
 [0, 0, 0], 
 [7, 0, 9]]
  • Justification: The element at position (1, 1) is zero. So, the second row and column are set to zero.

Example 2:

  • Input: matrix =
[[0, 2, 3], 
 [4, 5, 6], 
 [7, 8, 9]]

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible