Set Matrix Zeroes

Given a grid of integers, whenever a cell holds 0, set every cell in its row and every cell in its column to 0. Cells that were originally non-zero in other rows and columns stay unchanged.

Do the update in place: modify the grid you are given and return nothing. The tests inspect the grid after your function returns. A solution that uses a constant amount of extra memory is possible and is the one to aim for.

Constraints

  • 1 <= rows, columns <= 200
  • -2^31 <= matrix[i][j] <= 2^31 - 1

Examples

Example 1

Input: matrix = [[1,1,1],[1,0,1],[1,1,1]]
Output: [[1,0,1],[0,0,0],[1,0,1]]

The zero in the middle clears its row and its column, leaving only the four corners.

Example 2

Input: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]
Output: [[0,0,0,0],[0,4,5,0],[0,3,1,0]]

Two zeroes in the top row clear columns 0 and 3, and the whole top row.

Example 3

Input: matrix = [[1,2],[3,4]]
Output: [[1,2],[3,4]]

No zero means nothing changes.

JavaScript you'll use: Arrays: create, read, update

/**
 * @param {number[][]} matrix
 * @return {void}
 */
function setZeroes(matrix) {
  
}

Ctrl/⌘ + ' runs the examples, Ctrl/⌘ + Enter submits. Use console.log freely: output shows under Console. In the editor, press Esc then Tab to move focus out.