Furthest Building You Can Reach
MediumHeap / Priority Queue
Decode it first. Clues, constraints, pattern and plan before any code.You walk along a row of buildings with heights heights, starting at building 0. Moving to the next building is free if it is the same height or lower. If it is taller, you must climb the difference using either one ladder (any height) or that many bricks.
You have bricks bricks and ladders ladders. Using them as cleverly as possible, return the furthest building index you can reach.
heights = [4, 2, 7, 6, 9, 14, 12], bricks = 5, ladders = 1 → 4Climb 2 → 7 with 5 bricks, then 6 → 9 with the ladder. 9 → 14 needs 5 more bricks and you have none, so you stop at index 4.
Constraints
1 <= heights.length <= 10^51 <= heights[i] <= 10^60 <= bricks <= 10^90 <= ladders <= heights.length