FastPrepFurthest Building with Sandbags and Ropes
Problems/Furthest Building with Sandbags and Ropes

Furthest Building with Sandbags and Ropes

Zip logoZip● MediumFULLTIMENEW GRADPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: A first-hand Zip phone-screen report describes the building-height, sandbag, and rope task. A separate Zip candidate identified it as LeetCode 1642 and reported a follow-up asking which resource was used on each step. The graded interface and numeric limits use the official LeetCode formulation; the resource trace is discussed as a follow-up, not assumed to have a unique answer.

You travel through a row of buildings in order, starting at index 0. Moving to a building of equal or lower height is free. For an upward move of d height units, spend either d sandbags or one rope. A rope covers any upward height difference.

Given heights, the number of available sandbags, and the number of available ropes, return the largest building index you can reach. You may choose which climbs use ropes as you travel.

Function

furthestBuilding(heights: int[], sandbags: int, ropes: int) → int

Examples

Example 1

heights = [4,2,7,6,9,14,12]sandbags = 5ropes = 1return = 4

Use five sandbags for the climb from 2 to 7 and a rope for the climb from 6 to 9. The next uphill move cannot be paid for.

Example 2

heights = [2,6,7]sandbags = 1ropes = 1return = 2

Use the rope for the climb of four and one sandbag for the final climb.

Example 3

heights = [1,5,2,6]sandbags = 4ropes = 0return = 2

After spending four sandbags on the first climb, no resource remains for the final climb.

Constraints

  • 1 <= heights.length <= 100000.
  • 1 <= heights[i] <= 1000000.
  • 0 <= sandbags <= 1000000000.
  • 0 <= ropes <= heights.length.

More Zip problems

  • Maximum Survival Time in a Graph PursuitPHONE SCREEN · Seen Sep 2026
  • Find All Zip Rummy MeldsPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2026
  • Shortest Path Around Moving ParadesPHONE SCREEN · Seen Mar 2026
All Zip interview questionsSee Zip hiring insights
Saved
class Solution {
    public int furthestBuilding(int[] heights, int sandbags, int ropes) {
        // Write your code here.
    }
}
Checking account…