Furthest Building You Can Reach LeetCode solution in Python
1class Solution:2def furthestBuilding(self, H: List[int], B: int, L: int) -> int:3heap = []4for i in range(len(H) - 1):5diff = H[i + 1] - H[i]6if diff > 0:7if L > 0:8heappush(heap, diff)9L -= 110elif heap and diff > heap[0]:11heappush(heap, diff)12B -= heappop(heap)13else:14B -= diff15if B < 0:16return i17return len(H) - 1