Medium · Matrices

Fill Rows and Columns With 1s

Given an m × n matrix of 0s and 1s, modify it in place so that every row and every column that contains a 1 in the original matrix becomes all 1s; the function returns nothing.

Examples

Example 1

{
  "mat": [
    [0, 0, 0],
    [0, 1, 0],
    [0, 0, 0]
  ]
}

Output: [[0,1,0],[1,1,1],[0,1,0]]

Example 2

{
  "mat": [
    [0, 0, 0, 0],
    [0, 1, 0, 0],
    [0, 0, 0, 1],
    [0, 0, 0, 0]
  ]
}

Output: [[0,1,0,1],[1,1,1,1],[1,1,1,1],[0,1,0,1]]

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Matrices problems