C++ simple solution (accepted)

void Solution::setZeroes(vector<vector > &A) {
// Do not write main() function.
// Do not read input, instead use the arguments to the function.
// Do not print the output, instead return values as specified
// Still have a doubt. Checkout www.interviewbit.com/pages/sample_codes/ for more details
set ZerodRows;
set ZeroCols;
for (int i = 0; i< A.size(); ++i)
{
for (int j = 0; j < A[i].size(); ++j)
{
if (A[i][j] == 0 ) //mark
{
ZeroCols.insert(j);
ZerodRows.insert(i);
}
}
}

for (int i : ZerodRows)
{
for (int j = 0; j < A[0].size(); ++j)
{
A[i][j] = 0;
}
}

for (int j : ZeroCols)
{
for (int i = 0; i < A.size(); ++i)
{
A[i][j] = 0;
}
}
}

@roman-bober …can u tell when i use set like in ur solution ,it will be accepted .But if i use pair it will not be accepted.why set is memory effiecient ?

because set eliminates the duplicate ones … and pair does not

Click here to start solving coding interview questions