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.

Input: heights=[4,2,7,6,9,14,12], bricks=5, ladders=1 → Output: 4Input: heights=[4,12,2,7,3,18,20,3,19], bricks=10, ladders=2 → Output: 7

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.

import java.util.*; class Solution { public int furthestBuilding(int[] heights, int bricks, int ladders) { PriorityQueue<Integer> minHeap = new PriorityQueue<>(); for (int i = 0; i < heights.length - 1; i++) { int diff = heights[i + 1] - heights[i]; if (diff <= 0) continue; minHeap.offer(diff); if (minHeap.size() > ladders) { bricks -= minHeap.poll(); if (bricks < 0) return i; } } return heights.length - 1; } }