package leetcode;

/**
 * https://leetcode.com/problems/range-addition-ii/
 */
public class Problem598 {
    public int maxCount(int m, int n, int[][] ops) {
        if (ops.length == 0) {
            return m * n;
        }
        int[][] matrix = new int[m][n];
        int max = 0;
        int count = 0;
        for (int x = 0; x < ops.length; x++) {
            int[] op = ops[x];
            for (int i = 0; i < op[0]; i++) {
                for (int j = 0; j < op[1]; j++) {
                    matrix[i][j]++;
                    if (max < matrix[i][j]) {
                        max = matrix[i][j];
                        count = 1;
                    } else if (max == matrix[i][j]) {
                        count++;
                    }
                }
            }
        }
        return count;
    }

    public static void main(String[] args) {
        Problem598 prob = new Problem598();
        System.out.println(prob.maxCount(3, 3, new int[][]{
            {2, 2},
            {3, 3}
        })); // 4
        System.out.println(prob.maxCount(3, 3, new int[][]{
            {2, 1},
            {1, 3}
        })); // 1
        System.out.println(prob.maxCount(3, 3, new int[][]{
        })); // 9
        System.out.println(prob.maxCount(39999, 39999, new int[][]{
            {19999,  19999}
        })); // 399960001
    }
}

@@ -906,16 +906,18 @@
 m598();%0A
+//
         
@@ -960,32 +960,34 @@
 3, new int%5B%5D%5B%5D%7B%0A
+//
             %7B2, 
@@ -990,16 +990,18 @@
 %7B2, 2%7D,%0A
+//
         
@@ -1007,24 +1007,26 @@
      %7B3, 3%7D%0A
+//
         %7D));
@@ -1031,16 +1031,18 @@
 ); // 4%0A
+//
         
@@ -1085,32 +1085,34 @@
 3, new int%5B%5D%5B%5D%7B%0A
+//
             %7B2, 
@@ -1115,16 +1115,18 @@
 %7B2, 1%7D,%0A
+//
         
@@ -1136,16 +1136,18 @@
  %7B1, 3%7D%0A
+//
         
@@ -1156,16 +1156,18 @@
 ); // 1%0A
+//
         
@@ -1210,32 +1210,34 @@
 3, new int%5B%5D%5B%5D%7B%0A
+//
         %7D)); // 
@@ -1238,16 +1238,131 @@
 ); // 9%0A
+        System.out.println(prob.maxCount(6, 3, new int%5B%5D%5B%5D%7B%0A            %7B2, 2%7D, %7B5, 2%7D, %7B5, 1%7D%0A        %7D)); // 2%0A//
         
@@ -1413,32 +1413,34 @@
 9, new int%5B%5D%5B%5D%7B%0A
+//
             %7B199
@@ -1451,16 +1451,18 @@
  19999%7D%0A
+//
         

Update problem 598