FastPrepFurthest Building with Bricks and Ladders
Problems/Furthest Building with Bricks and Ladders

Furthest Building with Bricks and Ladders

Amazon logoAmazon● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Amazon full-time phone screen. The interviewer gave an array of building heights. You start at index 0 and move toward the end, going from index i to index i + 1. If the next building is not taller, you need no ladders or bricks. If it is taller, you use one ladder or h[i+1] - h[i] bricks, which is the height difference. The goal is the furthest index you can reach if you use bricks and ladders in the best way. The follow-up asked about using binary search to speed it up.

The report does not give limits on the array or on the number of bricks and ladders. Here, there are up to 10^5 buildings, heights are at most 10^6, and you can have up to 10^9 bricks. The binary-search follow-up is covered in the editorial, not checked.

Our version is about 95% the same as the reported question.

You are given an integer array heights, where heights[i] is the height of building i. You start at building 0 and move to the next building one step at a time, from building i to building i + 1.

When you move from building i to building i + 1:

  • If heights[i] >= heights[i + 1], the move is free.
  • If heights[i] < heights[i + 1], you must use either one ladder or exactly heights[i + 1] - heights[i] bricks.

You have bricks bricks and ladders ladders. Each brick and each ladder can be used only once, and one ladder covers a climb of any height.

Return the largest building index you can reach if you choose the bricks and ladders for each climb in the best way.

Function

furthestBuilding(heights: int[], bricks: int, ladders: int) → int

Examples

Example 1

heights = [3,1,4,8,6,10]bricks = 4ladders = 1return = 4

The climbs are 1 → 4 (3), 4 → 8 (4), and 6 → 10 (4). The moves 3 → 1 and 8 → 6 are free.

To reach building 4, use the ladder on the climb of 4 and three bricks on the climb of 3. One brick is left.

Building 5 would need all three climbs paid for. One ladder covers one of them, and the other two need at least 3 + 4 = 7 bricks, but there are only 4. So the answer is 4.

Example 2

heights = [1,2,3,100]bricks = 2ladders = 1return = 3

The climbs are 1, 1, and 97. Use the two bricks on the two small climbs and save the ladder for the climb of 97. You reach the last building, index 3.

If you used the ladder on the first climb, you could not pay for the climb of 97 with one brick.

Example 3

heights = [5,5,5]bricks = 0ladders = 0return = 2

Every move is to a building of the same height, so every move is free and you reach index 2.

Example 4

heights = [2,7,4,9]bricks = 0ladders = 1return = 2

Use the ladder for the climb from 2 to 7. The move from 7 to 4 is free. The climb from 4 to 9 needs 5 bricks or a ladder, and you have neither, so you stop at index 2.

Constraints

  • 1 <= heights.length <= 10^5
  • 1 <= heights[i] <= 10^6
  • 0 <= bricks <= 10^9
  • 0 <= ladders <= heights.length

More Amazon Phone Screen questions

  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 3SumPHONE SCREEN · Seen Nov 2026
  • Circular Primes Below a LimitPHONE SCREEN · Seen Nov 2026
  • Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Two SumOA · PHONE SCREEN · Seen Nov 2026
  • Count the 1 Bits in a 32-Bit ValuePHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Maximum Number of Events That Can Be AttendedByteDance · PHONE SCREENByteDance interview questions
  • Defer Expenses to Preserve BalanceDRW · PHONE SCREENDRW interview questions
  • Minimize Array Sum After K Halving OperationsDocuSign · PHONE SCREENDocuSign interview questions
  • Maximum Number of Events That Can Be AttendedSnowflake · PHONE SCREENSnowflake interview questions
  • Automation Pipeline, Part 3: Stage DurationPlaid · PHONE SCREENPlaid interview questions
  • Finish Ordered CPU Tasks with the Fewest CPUsGoogle · PHONE SCREENGoogle interview questions
  • Minimum Sum After K Ceiling HalvingsAdobe · PHONE SCREENAdobe interview questions
  • Maximize the Minimum Cone DistanceSumo Logic · PHONE SCREEN
  • Schedule Unit-Time Jobs for the Most ProfitScale AI · PHONE SCREENScale AI interview questions

Amazon interview experiences

  • Amazon SWE OA with AI Coding: 1 Experience
  • Amazon SWE Intern Phone Screen Interview Experience: 1 Experience
  • Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
  • Amazon BIE Intern SQL and Interview Questions: 17 Experiences
  • Amazon Experienced SWE AI-Assisted Debugging OA: 1 Experience
  • Amazon SDE II (L5) Interview Questions: 5 Experiences
See Amazon hiring insights
Saved
class Solution {
    public int furthestBuilding(int[] heights, int bricks, int ladders) {
        // Write your solution here.
    }
}
Checking account…