package leetcode;

/**
 * https://leetcode.com/problems/largest-submatrix-with-rearrangements/
 */
public class Problem1727 {
    public int largestSubmatrix(int[][] matrix) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1727 prob = new Problem1727();
        System.out.println(prob.largestSubmatrix(new int[][]{
            {0,0,1},{1,1,1},{1,0,1}
        })); // 4
        System.out.println(prob.largestSubmatrix(new int[][]{
            {0,0,1,1,1},{1,1,1,0,1},{1,0,1,0,1}
        })); // 6
        System.out.println(prob.largestSubmatrix(new int[][]{
            {0,0,1,1,0},{1,1,1,0,1},{1,0,1,0,1}
        })); // 6
        System.out.println(prob.largestSubmatrix(new int[][]{
            {1,0,1,0,1}
        })); // 3
        System.out.println(prob.largestSubmatrix(new int[][]{
            {1,0,1,0},{0,1,0,1}
        })); // 2
        System.out.println(prob.largestSubmatrix(new int[][]{
            {1,1,0},{1,0,1}
        })); // 2
        System.out.println(prob.largestSubmatrix(new int[][]{
            {0,0},{0,0}
        })); // 0
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -207,565 +207,325 @@
     
-// TODO%0A        return 0
+int maxRow = matrix.length
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1727 prob = new Problem1727();%0A        System.out.println(prob.largestSubmatrix(new int%5B%5D%5B%5D%7B%0A            %7B0,0,1%7D,%7B1,1,1%7D,%7B1,0,1%7D%0A        %7D)); // 4%0A        System.out.println(prob.largestSubmatrix(new int%5B%5D%5B%5D%7B%0A            %7B0,0,1,1,1%7D,%7B1,1,1,0,1%7D,%7B1,0,1,0,1%7D%0A        %7D)); // 6%0A        System.out.println(prob.largestSubmatrix(new int%5B%5D%5B%5D%7B%0A            %7B0,0,1,1,0%7D,%7B1,1,1,0,1%7D,%7B1,0,1,0,1%7D%0A        %7D)); // 6%0A        System.out.println(prob.largestSubmatrix(new int%5B%5D%5B%5D%7B
+int maxCol = maxRow %3E 0 ? matrix%5B0%5D.length : 0;%0A        for (int col = 0; col %3C maxCol; col++) %7B%0A            int count = 0;%0A            for (int row = 0; row %3C maxRow; row++) %7B%0A                count = matrix%5Brow%5D%5Bcol%5D == 0 ? 0 : count + 1;%0A                matrix%5Brow%5D%5Bcol%5D = count;
 %0A   
@@ -537,18 +537,8 @@
     
-%7B1,0,1,0,1
 %7D%0A  
@@ -548,16 +548,8 @@
    %7D
-)); // 3
 %0A   
@@ -557,281 +557,205 @@
     
-System.out.println(prob.largestSubmatrix(new int%5B%5D%5B%5D%7B%0A            %7B1,0,1,0%7D,%7B0,1,0,1%7D%0A        %7D)); // 2%0A        System.out.println(prob.largestSubmatrix(new int%5B%5D%5B%5D%7B%0A            %7B1,1,0%7D,%7B1,0,1%7D%0A        %7D)); // 2%0A        System.out.println(prob.largestSubmatrix(new int%5B%5D%5B%5D%7B
+int answer = 0;%0A        for (int%5B%5D m : matrix) %7B%0A            Arrays.sort(m);%0A            for (int col = 0; col %3C maxCol; col++) %7B%0A                answer = Math.max(answer, m%5Bcol%5D * (maxCol - col));
 %0A   
@@ -767,18 +767,8 @@
     
-%7B0,0%7D,%7B0,0
 %7D%0A  
@@ -778,16 +778,31 @@
    %7D
-)); // 0
+%0A        return answer;
 %0A   

Solve problem 1727