“This is the 7th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

Hope is a good thing, maybe the best of things. And no good thing ever dies.

The title

Given a matrix M of size m by n with zero initial elements and a series of update operations on m.

The operations are represented by a two-dimensional array, where each operation is represented by an array of two positive integers A and b. The implication is to increment the value of all elements M[I][j] that match 0 <= I < a and 0 <= j < b by one.

After performing a given sequence of operations, you need to return the number of elements in the matrix that contain the largest integer.

Example:

Input: m = 3, n = 3 operations = [[2,2],[3,3] Initial state, M = [[0, 0, 0], [0, 0, 0], [0, 0, 0]] execute after the operation (2, 2], M = [[1, 1, 0], [1, 1, 0], [0, 0, 0]] after [3, 3] after the operation, M = [[2, 2, 1], [2, 2, 1], [1, 1]] The largest integer in M is 2, and there are four elements in M with the value of 2. So return 4.Copy the code

Analysis of the

Each operation is a rectangle from (0, 0) to (a, b) in the upper left corner, which must overlap, so take the smallest a times the smallest B.

The area formed by the horizontal and vertical coordinates (x,y) in all ops[I] and the upper left corner (0,0) is guaranteed to be covered by each operation, and x∗y is the desired result (or intersection of all operations).

Each time the operations element is executed, the M * N two-dimensional array executes +1 from position (0, 0) to the coordinates represented by the operations value (x,y), so the maximum value is the most frequently executed two-dimensional coordinate position, The x and y values of the minimum coordinate in Operations is the maximum.

The problem solving

var maxCount = function(m, n, ops) { let mina = m, minb = n; Mina = math.min (mina, op[0]); for (const op of ops) {mina = math.min (mina, op[0]); minb = Math.min(minb, op[1]); Return mina * minb; };Copy the code

conclusion

If this article helped you, please like 👍 and follow ⭐️.

If there are any errors in this article, please correct them in the comments section 🙏🙏

Welcome to pay attention to my wechat public number, exchange technology together, wechat search 🔍 : “fifty years later”