Farthest Rack a Cable Run Reaches With Limited Ladders and Bricks

Last updated: November 29, 2026

Quick Overview

Rack heights are given left to right. Moving to a taller rack requires either one ladder or bricks equal to the height difference. Return the farthest rack index you can reach.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Rack heights are given left to right. Moving to a taller rack requires either one ladder or bricks equal to the height difference. Return the farthest rack index you can reach.

A Meta onsite greedy question with a data center twist. The key idea interviewers look for is that ladders should cover the largest climbs, which a size-limited min-heap tracks online without knowing the future.

What the Interviewer Expects
  • See that only upward steps cost anything
  • Assign ladders to the largest climbs seen so far
  • Maintain a min-heap of ladder-covered climbs, size at most `ladders`
  • Pay the smallest climb with bricks when the heap overflows
  • Return the index where bricks first go negative
Key Topics to Cover
greedy
min-heap
resource allocation
online algorithm
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if bricks and ladders have different costs and you minimize cost to reach the end?
  • Can you answer this with binary search plus sorting instead?
  • What if you can also go back and reuse resources?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: heights, bricks >= 0, ladders >= 0.
  • Going down or level is free.
  • Return the largest index reachable starting from index 0....
High-Level Design

If we knew all climbs up to some index, the best allocation would give ladders to the ladders largest climbs and pay the rest in bricks. We can maintain that allocation online:

  • Push each posi...

Submit Your Answer
Markdown supported