This question was asked to me during the problem solving round of Infra.Market
That time I was not able to solve the problem, as I have never been able to solve coding problems during these situations.
But here I am giving my solution if it helps you.
Question : You are given a matrix which has both rows & columns sorted. And the matrix has only 0s & 1s. So you may have got the idea about the kind of input.
It will be like -
{0,0,0,0,1},
{0,0,0,1,1},
{0,1,1,1,1},
{0,1,1,1,1},
{1,1,1,1,1}
and answer for this will be-
1,1,1,1
1,1,1,1
1,1,1,1
Below is my solution, please comment for the issues & the improvements in this, to help others also.
That time I was not able to solve the problem, as I have never been able to solve coding problems during these situations.
But here I am giving my solution if it helps you.
Question : You are given a matrix which has both rows & columns sorted. And the matrix has only 0s & 1s. So you may have got the idea about the kind of input.
It will be like -
{0,0,0,0,1},
{0,0,0,1,1},
{0,1,1,1,1},
{0,1,1,1,1},
{1,1,1,1,1}
and answer for this will be-
1,1,1,1
1,1,1,1
1,1,1,1
Below is my solution, please comment for the issues & the improvements in this, to help others also.
Matrix