Set Matrix Zeroes

Medium Solved

Description

Given an m × n integer matrix, if an element is 0, set its entire row and column to 0.

You must do it in place.

Input format:

  • Line 1: JSON 2D array representing the matrix

Examples

Input:
[[1,1,1],[1,0,1],[1,1,1]]

Output:
[[1,0,1],[0,0,0],[1,0,1]]
Input:
[[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]]

Note:

Print the final matrix as a JSON array.

No submissions yet.

Discuss brute-force vs constant space optimization using first row and first column as markers.

Test Cases