package leetcode;

import java.util.List;

/**
 * https://leetcode.com/problems/reconstruct-a-2-row-binary-matrix/
 */
public class Problem1253 {
    public List<List<Integer>> reconstructMatrix(int upper, int lower, int[] colsum) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1253 prob = new Problem1253();
        System.out.println(prob.reconstructMatrix(2, 1, new int[]{1, 1, 1})); // [[1,1,0],[0,0,1]]
        System.out.println(prob.reconstructMatrix(2, 3, new int[]{2,2,1,1})); // []
        System.out.println(prob.reconstructMatrix(5, 5, new int[]{2,1,2,0,1,0,1,2,0,1})); // [[1,1,1,0,1,0,0,1,0,0],[1,0,1,0,0,0,1,1,0,1]]
    }
}

@@ -12,16 +12,74 @@
 tcode;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.Collections;%0A
 import j
@@ -296,35 +296,976 @@
     
-// TODO%0A        return null
+List%3CList%3CInteger%3E%3E answer = new ArrayList%3C%3E();%0A        answer.add(new ArrayList%3C%3E());%0A        answer.add(new ArrayList%3C%3E());%0A        int twoCounts = 0;%0A        for (int i = 0; i %3C colsum.length; i++) %7B%0A            if (colsum%5Bi%5D == 2) %7B%0A                answer.get(0).add(1);%0A                answer.get(1).add(1);%0A                twoCounts++;%0A            %7D else %7B%0A                answer.get(0).add(0);%0A                answer.get(1).add(0);%0A            %7D%0A        %7D%0A        int up = upper - twoCounts;%0A        int lo = lower - twoCounts;%0A        for (int i = 0; i %3C colsum.length; i++) %7B%0A            if (colsum%5Bi%5D == 1) %7B%0A                if (up %3E 0) %7B%0A                    answer.get(0).set(i, 1);%0A                    up--;%0A                %7D else if (lo %3E 0) %7B%0A                    answer.get(1).set(i, 1);%0A                    lo--;%0A                %7D else %7B%0A                    return Collections.emptyList();%0A                %7D%0A            %7D%0A        %7D%0A        return answer
 ;%0A  
@@ -1356,24 +1356,26 @@
 blem1253();%0A
+//
         Syst
@@ -1457,24 +1457,26 @@
 0%5D,%5B0,0,1%5D%5D%0A
+//
         Syst
@@ -1547,16 +1547,18 @@
 ; // %5B%5D%0A
+//
         
@@ -1688,16 +1688,131 @@
 1,0,1%5D%5D%0A
+        System.out.println(prob.reconstructMatrix(1, 4, new int%5B%5D%7B2,1,2,0,0,2%7D)); // %5B%5B1,0,1,0,0,1%5D,%5B1,1,1,0,0,1%5D%5D%0A
     %7D%0A%7D%0A

Update problem 1253