Given heights[], bricks, and ladders, move through buildings using bricks for small climbs and save ladders for the largest climbs. Find the farthest building index you can reach.
Greedy with a min-heap: when we need to climb, first use a ladder. Track all ladder-used climbs in a min-heap. If heap size exceeds ladders, replace the smallest ladder-used climb with bricks instead.
- Min-heap stores climb heights where ladders were used.
- For each climb diff = heights[i+1] - heights[i] > 0:
- Push diff into heap.
- If heap.size() > ladders: pop min from heap (now use bricks for that), bricks -= min.
- If bricks < 0: cannot proceed, return i.
- Time Complexity: O(N log L) where L = ladders
- Space Complexity: O(L)