void setMatrixZeroes(vector<vector<int>> &mat) {
// code here
int row = mat.size(), col = mat[0].size();
bool isFirstRow = false, isFirstCol = false;
// check 0th row and 0th col, if value is 0
for(int j=0; j<col; j++) {
if(mat[0][j] == 0)
isFirstRow = true;
}
for(int i=0; i<row; i++) {
if(mat[i][0] == 0)
isFirstCol = true;
}
// mark from 1st row and 1st col to nth row and mth col
for(int i=1; i<row; i++) {
for(int j=1; j<col; j++) {
if(mat[i][j] == 0) {
mat[i][0] = 0;
mat[0][j] = 0;
}
}
}
// fill 0 from 1st row and 1st col to nth row and mth col
for(int i=1; i<row; i++) {
for(int j=1; j<col; j++) {
if(mat[i][0] == 0 || mat[0][j] == 0)
mat[i][j] = 0;
}
}
//fill the first row and first col to 0
if(isFirstRow) {
for(int j=0; j<col; j++)
mat[0][j] = 0;
}
if(isFirstCol) {
for(int i=0; i<row; i++)
mat[i][0] = 0;
}
}