1
var furthestBuilding = function (heights, bricks, ladders) {2
const heap = new MaxPriorityQueue({ priority: (x) => x });6
for (i = 0; i < heights.length - 1; i++) {7
if (heights[i] >= heights[i + 1]) continue;9
const diff = heights[i + 1] - heights[i];11
// if not enough bricks are left13
// if not enough ladders are left14
if (ladders === 0) break;16
// if the max bricks used at once > current jump17
// replace the max bricks with a ladder and use those bricks for current jump18
// else use ladder for the current jump19
if (!heap.isEmpty() && heap.front().element > diff) {20
bricks += heap.dequeue().element - diff;25
// greedly use bricks when possible