package com.interview.dynamic;

/**
 * http://www.geeksforgeeks.org/maximum-size-sub-matrix-with-all-1s-in-a-binary-matrix/
 */
public class MaximumSizeSubMatrix {

    private int min(int a,int b, int c){
        int l = Math.min(a, b);
        return Math.min(l, c);
    }
    
    public int maxSize(int arr[][]){
        
        int result[][] = new int[arr.length][arr[0].length];
        
        for(int i=0; i < arr.length; i++){
            result[i][0] = arr[i][0];
        }
        
        for(int i=0; i < arr[0].length; i++){
            result[0][i] = arr[0][i];
        }
        
        int max = 1;
        for(int i=1; i < arr.length; i++){
            for(int j=1; j < arr[i].length; j++){
                if(arr[i][j] == 0){
                    continue;
                }
                int t = min(result[i-1][j],result[i-1][j-1],result[i][j-1]);
                result[i][j] =  t +1;
                if(result[i][j] > max){
                    max = result[i][j];
                }
            }
        }
        return max;
    }
    
    
    public static void main(String args[]){
        
        int arr[][] = {{0,1,1,0,1},{1,1,1,0,0},{1,1,1,1,0},{1,1,1,0,1}};
        MaximumSizeSubMatrix mssm = new MaximumSizeSubMatrix();
        int result = mssm.maxSize(arr);
        System.out.print(result);
    }
    
}

@@ -380,32 +380,44 @@
 ength%5D;%0A        
+int max = 0;
 %0A        for(int
@@ -482,16 +482,104 @@
 %5Bi%5D%5B0%5D;%0A
+            if (result%5Bi%5D%5B0%5D == 1)%0A            %7B%0A                max = 1;%0A            %7D%0A
         
@@ -673,16 +673,117 @@
 %5B0%5D%5Bi%5D;%0A
+            if (result%5B0%5D%5Bi%5D == 1)%0A            %7B%0A                max = 1;%0A            %7D%0A            %0A
         
@@ -805,20 +805,8 @@
     
-int max = 1;
 %0A   

Update to maxSize method