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

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Matrices problems