One Pager Cheat Sheet
- Write a method to return the frequency of the highest value in a 2D matrix array, which is initially prefilled with 0s, where the size of the array is
mrows andncolumns, and given a list of increment operations in the form of a two-number array[row, column]. - Given the operations
[1,1]and then[2,2]on a blank state of all0s, we obtain a modified state of2s. - The
largest numberin theupper leftof thematrixwasincrementedby1due to theoverlapof the twooperations. - The cells with the greatest numbers can be found by looking at the edges of the range of each operation, as these are guaranteed to be layered over the most, with
O(n)complexity.
This is our final solution.
To visualize the solution and step through the below code, click Visualize the Solution on the right-side menu or the VISUALIZE button in Interactive Mode.
xxxxxxxxxx45
}var assert = require('assert');​function maxFromOps(m, n, operations) { var minCol = m; var minRow = n;​ for (let op of operations) { minCol = Math.min(minCol, op[0]); minRow = Math.min(minRow, op[1]); } return minCol * minRow;}​try { assert.equal( maxFromOps(4, 4, [ [1, 1], [2, 2], ]), 1 );​ console.log( 'PASSED: ' + 'Expect `maxFromOps(4, 4, [[1, 1], [2, 2]])` to return `1`' );} catch (err) { console.log(err);}​try { assert.equal( maxFromOps(4, 4, [OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment
Great job getting through this. Let's move on.
If you had any problems with this tutorial, check out the main forum thread here.


