PIXELBANKv9.1.0
Menu

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 locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.