int getMaxOneRow()
{
...int maxOne = 0, maxRow = 0;
...for (curRow=0; curRow<rowSize; curRow++)
...{
......int n = getOneCount(curRow);
......if(n > maxOne)
......{
.........maxOne = n;
.........maxRow = curRow;
......}
...}
return maxRow;
}

int getOneCount(int row)
{
...int count =0;
...for(int i =0; i<columnSize; i++)
...{
......if(matrix[row][i] == 1)
......{
......  count++;
......}
...}
}


time complexity O(n^2)
space complexity O(1)


On Sep 21, 9:51 pm, "coolfrog$" <dixit.coolfrog.div...@gmail.com>
wrote:
> There is a 2 dimensional array with each cell containing a 0 or 1 ,
>  Design an algorithm to
> find out which row has the maximum number of 1's , Your algorithm should
> have O(n2)
> time and no space complexity.

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

Reply via email to