JSFiddle - React, Tailwind, and code Playground
by Sudheer Nunna
JavaScript
var setZeroes = function(matrix) {
const row = matrix.length;
const col = matrix[0].length;
const dummyRow = new Array(row).fill(-1);
const dummyCol = new Array(col).fill(-1);
for(let i=0;i<row;i++){
for(let j=0;j<col;j++){
if(matrix[i][j] === 0){
dummyRow[i] = 0;
dummyCol[j] = 0;
}
}
}
for(let i=0;i<dummyRow.length;i++){
for(let j=0;i<dummyCol.length;j++){
if(dummyRow[i]===0 || dummyCol[j] === 0){
matrix[i][j] = 0;
}
}
console.log(matrix)
}
console.log(dummyRow)
console.log(dummyCol)
}
setZeroes([[1,1,1],[1,0,1],[1,1,1]])