Range Addition II

easy math

Problem

Start with an m×n zero matrix. Each op [a, b] increments cells in [0..a)×[0..b). Return count of cells equal to the max.

Inputm=3 n=3 ops=[[2,2],[3,3]]
Output4
Min a=2, min b=2; intersection cells = 2·2 = 4.

def max_count(m, n, ops):
    if not ops: return m * n
    a = min(o[0] for o in ops); b = min(o[1] for o in ops)
    return a * b
function maxCount(m, n, ops) {
  if (!ops.length) return m * n;
  const a = Math.min(...ops.map(o => o[0])), b = Math.min(...ops.map(o => o[1]));
  return a * b;
}
int maxCount(int m, int n, int[][] ops) {
    if (ops.length == 0) return m * n;
    int a = Integer.MAX_VALUE, b = Integer.MAX_VALUE;
    for (int[] o : ops) { a = Math.min(a, o[0]); b = Math.min(b, o[1]); }
    return a * b;
}
int maxCount(int m, int n, vector>& ops) {
    if (ops.empty()) return m * n;
    int a = INT_MAX, b = INT_MAX;
    for (auto& o : ops) { a = min(a, o[0]); b = min(b, o[1]); }
    return a * b;
}
Time: O(k) Space: O(1)