package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/matrix-block-sum/
 */
public class Problem1314 {
    public int[][] matrixBlockSum(int[][] mat, int K) {
        // TODO
        return null;
    }

    private static void print(int[][] mat) {
        for (int[] m : mat) {
            System.out.println(Arrays.toString(m));
        }
    }

    public static void main(String[] args) {
        Problem1314 prob = new Problem1314();
        print(prob.matrixBlockSum(new int[][]{
            {1,2,3},{4,5,6},{7,8,9}
        }, 1)); // [[12,21,16],[27,45,33],[24,39,28]]
        print(prob.matrixBlockSum(new int[][]{
            {1,2,3},{4,5,6},{7,8,9}
        }, 2)); // [[45,45,45],[45,45,45],[45,45,45]]
    }
}

@@ -176,24 +176,806 @@
 t, int K) %7B%0A
+        int maxRow = mat.length;%0A        int maxCol = maxRow %3E 0 ? mat%5B0%5D.length : 0;%0A        int%5B%5D%5B%5D rowSums = new int%5BmaxRow%5D%5BmaxCol%5D;%0A        int%5B%5D%5B%5D colSums = new int%5BmaxRow%5D%5BmaxCol%5D;%0A        for (int row = 0; row %3C maxRow; row++) %7B%0A            for (int col = 0; col %3C maxCol; col++) %7B%0A                if (col == 0) %7B%0A                    colSums%5Brow%5D%5Bcol%5D = mat%5Brow%5D%5Bcol%5D;%0A                %7D else %7B%0A                    colSums%5Brow%5D%5Bcol%5D = colSums%5Brow%5D%5Bcol - 1%5D + mat%5Brow%5D%5Bcol%5D;%0A                %7D%0A                if (row == 0) %7B%0A                    rowSums%5Brow%5D%5Bcol%5D = mat%5Brow%5D%5Bcol%5D;%0A                %7D else %7B%0A                    rowSums%5Brow%5D%5Bcol%5D = rowSums%5Brow - 1%5D%5Bcol%5D + mat%5Brow%5D%5Bcol%5D;%0A                %7D%0A            %7D%0A        %7D%0A        int%5B%5D%5B%5D answer = new int%5BmaxRow%5D%5BmaxCol%5D;%0A
         // T
@@ -997,12 +997,14 @@
 urn 
-null
+answer
 ;%0A  
@@ -1306,32 +1306,58 @@
     %7B1,2,3%7D,
-%7B4,5,6%7D,
+%0A            %7B4,5,6%7D,%0A            
 %7B7,8,9%7D%0A    
@@ -1406,16 +1406,18 @@
 39,28%5D%5D%0A
+//
         
@@ -1447,32 +1447,34 @@
 um(new int%5B%5D%5B%5D%7B%0A
+//
             %7B1,2
@@ -1481,24 +1481,54 @@
 ,3%7D,
-%7B4,5,6%7D,
+%0A//            %7B4,5,6%7D,%0A//            
 %7B7,8,9%7D%0A
     
@@ -1515,32 +1515,34 @@
         %7B7,8,9%7D%0A
+//
         %7D, 2)); 

Update problem 1314