1642. Furthest Building You Can Reach
On This Page
class Solution:
def furthestBuilding(self, heights: List[int], bricks: int, ladders: int) -> int:
h = []
for i, a in enumerate(heights[:-1]):
b = heights[i + 1]
d = b - a
if d > 0:
heappush(h, d)
if len(h) > ladders:
bricks -= heappop(h)
if bricks < 0:
return i
return len(heights) - 1