Boolean matrix

Given a boolean matrix, modify it so that if a cell contains 1, all cells in its row and column are set to 1. Mark row i and column j to 1 if matrix[i][j] = 1.

Hint

To keep track of changes in the original matrix, we create a new "mirror" matrix. Initially, all the cells in this mirror matrix are empty. This mirror matrix will be used to record information about the changes that occur during the algorithm's execution.

# Python implementation
matrix = [
  [0, 0, 0, 0, 1],
  [0, 1, 0, 0, 0],
  [0, 0, 0, 0, 0],
  [1, 0, 0, 0, 0],
  [0, 0, 0, 1, 0]
]

output = [["" for x in y] for y in matrix]
h = len(matrix)
w = len(matrix[0])

for i in range(h):
  for j in range(w):
    if matrix[i][j] == 1:
      for k in range(w):
        output[i][k] = 1

      for k in range(h):
        output[k][j] = 1

print(output)
// Javascript implementation
const matrix = [
  [0, 0, 0, 0, 1],
  [0, 1, 0, 0, 0],
  [0, 0, 0, 0, 0],
  [1, 0, 0, 0, 0],
  [0, 0, 0, 1, 0]
];

const output = matrix.map(item => item.map(i => ""));
const h = matrix.length;
const w = matrix[0].length;

for (let i = 0; i < h; i++) {
  for (let j = 0; j < w; j++) {
    if (matrix[i][j] == 1) {
      for (let k = 0; k < w; k++) {
        output[i][k] = 1
      }

      for (let k = 0; k < h; k++) {
        output[k][j] = 1;
      }
    }
  }
}

console.log(output);