Farthest rooftop with bricks and ladders
Rooftops stand in a row with heights heights. You start on rooftop 0 and move right one rooftop at a time. Stepping to a rooftop that is not taller is free; climbing up by d costs either d bricks or one ladder, which covers any climb. You have bricks bricks and ladders ladders, and each brick and each ladder can be used only once. Return the index of the farthest rooftop you can reach if you spend them as well as possible.
Aim for O(n log L) with L ladders, instead of re-planning the whole route at every step.
Besides the tests, one large input (8,000 rising rooftops) with a ~200 ms limit (scaled to your device's speed): brute force won't pass.
Examples
farthest_rooftop([4,2,7,6,9,14,12], 5, 1)→4farthest_rooftop([4,12,2,7,3,18,20,3,19], 10, 2)→7farthest_rooftop([14,3,19,3], 17, 0)→3