Easy

Quiz

#598 Range Addition II

APPROACH

You have an m x n matrix of zeros. Each operation ops[i] = [ai, bi] adds 1 to every cell M[x][y] where 0 <= x < ai and 0 <= y < bi. After applying all operations, count and return how many cells hold the maximum value.

Example 1:

Input: m = 3, n = 3, ops = [[2,2],[3,3]]
Output: 4
Explanation: The maximum integer in M is 2, and there are four of it in M. So return 4.

Example 2:

Input: m = 3, n = 3, ops = [[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3]]
Output: 4

Example 3:

Input: m = 3, n = 3, ops = []
Output: 9
1 of 4
1:00

What is the optimal approach for this problem?