PIXELBANKv8.2.1
Menu

Set Matrix Zeroes

Given an m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place.

Output matrix rows, space-separated.

Example:

Input:
1,1,1
1,0,1
1,1,1
Output:
1 0 1
0 0 0
1 0 1
Reasoning:
  • The input matrix is: 1 1 1 1 0 1 1 1 1
  • We identify the rows and columns that contain a 0, which are row 2 and column 2.
  • We set the entire row 2 to 0 and the entire column 2 to 0, resulting in: 1 0 1 0 0 0 1 0 1
  • The final output is the modified matrix, with the specified rows and columns set to 0.

Constraints:

  • 1 <= m, n <= 200
  • -2^31 <= matrix[i][j] <= 2^31 - 1
Editor

Test Results

0/0
Run code to see test results.