int row = 0;
int col = 0;
int prevColCnt = 0;
int rowMax = 0;

while (row < N)
{
  while (col < N)
     A[row][col] == 1 ? col++ : break;
  if (prevColCnt < col)
  {
     prevColCnt = col;
     rowMax = row;
  }
  row++;
}

printf("%d", rowMax);

If there are more than one rows with max 1's, then rowMax will give u
the first row with max. no. of 1's.
In case u want all max rows then you can have a stack to keep track of
all rows with max. 1's.

On Dec 27, 12:24 am, jyoti saini <[email protected]> wrote:
> A NxN matrix is given containing only 1’s and 0’s. Every row is sorted in
> descending order. Find the row containing maximum no. of ones.
> time complexity-O(n);
> --
>
> Jyoti Saini.
> B.Tech-Final year.
> Information Technology.
> National Institute of Technology,Kurukshetra.
> Alt Email [email protected] <[email protected]>
> +91-9813799528,+91-8030776217, 0172-4635398.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to