To find the row with max zero Matrix will have either 0 or 1 in sorted manner.

 public static void main(String[] args) {
    // TODO Auto-generated method stub
    int[][] inp=new int[][]{
    int j=0,rownum=0;       
    for(int i=0;i<4;i++){
    System.out.println("Row "+(rownum+1)+" has Max zero");


Complexity of the above program is \$O(m+n)\$ where \$m\$ is row size and \$n\$ is column size.

If any better approach is there then please post in this


I do not think you can do something to reduce Complexity in any traditional way. You have to traverse all array elements in order to find the row with the max element,so m x n iterations will give you O(m+n) Complexity.

  • \$\begingroup\$ reversing is additional operation. I have already written program with O(m+n). I wanted to find any other way or approach with minimal complexity than O(m+n) \$\endgroup\$ – Mohan Raj May 9 '15 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.