package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/find-valid-matrix-given-row-and-column-sums/
 */
public class Problem1605 {
    public int[][] restoreMatrix(int[] rowSum, int[] colSum) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1605 prob = new Problem1605();
        // [[3,0],
        //  [1,7]]
        System.out.println(Arrays.toString(
            prob.restoreMatrix(new int[]{3,8}, new int[]{4,7})
        ));
        // [[0,5,0],
        //  [6,1,0],
        //  [2,0,8]]
        System.out.println(Arrays.toString(
            prob.restoreMatrix(new int[]{5,7,10}, new int[]{8,6,8})
        ));
        // [[0,9,5],
        //  [6,0,3]]
        System.out.println(Arrays.toString(
            prob.restoreMatrix(new int[]{14,9}, new int[]{6,9,8})
        ));
        // [[1],
        //  [0]]
        System.out.println(Arrays.toString(
            prob.restoreMatrix(new int[]{1,0}, new int[]{1})
        ));
        // [[0]]
        System.out.println(Arrays.toString(
            prob.restoreMatrix(new int[]{0}, new int[]{0})
        ));
    }
}

@@ -16,34 +16,8 @@
 e;%0A%0A
-import java.util.Arrays;%0A%0A
 /**%0A
@@ -200,924 +200,363 @@
     
-// TODO%0A        return null;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem1605 prob = new Problem1605();%0A        // %5B%5B3,0%5D,%0A        //  %5B1,7%5D%5D%0A        System.out.println(Arrays.toString(%0A            prob.restoreMatrix(new int%5B%5D%7B3,8%7D, new int%5B%5D%7B4,7%7D)%0A        ));%0A        // %5B%5B0,5,0%5D,%0A        //  %5B6,1,0%5D,%0A        //  %5B2,0,8%5D%5D%0A        System.out.println(Arrays.toString(%0A            prob.restoreMatrix(new int%5B%5D%7B5,7,10%7D, new int%5B%5D%7B8,6,8%7D)%0A        ));%0A        // %5B%5B0,9,5%5D,%0A        //  %5B6,0,3%5D%5D%0A        System.out.println(Arrays.toString(%0A            prob.restoreMatrix(new int%5B%5D%7B14,9%7D, new int%5B%5D%7B6,9,8%7D)%0A        ));%0A        // %5B%5B1%5D,%0A        //  %5B0%5D%5D%0A        System.out.println(Arrays.toString(%0A            prob.restoreMatrix(new int%5B%5D%7B1,0%7D, new int%5B%5D%7B1%7D)%0A        ));%0A        // %5B%5B0%5D%5D%0A        System.out.println(Arrays.toString(%0A            prob.restoreMatrix(new int%5B%5D%7B0%7D, new int%5B%5D%7B0%7D)%0A        ))
+int%5B%5D%5B%5D answer = new int%5BrowSum.length%5D%5BcolSum.length%5D;%0A        for (int i = 0; i %3C rowSum.length; ++i) %7B%0A            for (int j = 0 ; j %3C colSum.length; ++j) %7B%0A                answer%5Bi%5D%5Bj%5D = Math.min(rowSum%5Bi%5D, colSum%5Bj%5D);%0A                rowSum%5Bi%5D -= answer%5Bi%5D%5Bj%5D;%0A                colSum%5Bj%5D -= answer%5Bi%5D%5Bj%5D;%0A            %7D%0A        %7D%0A        return answer
 ;%0A  

Solve problem 1605