Count Ways to Climb a Warehouse Ladder Avoiding Broken Rungs

Last updated: November 29, 2026

Quick Overview

A warehouse associate climbs a ladder from rung 0 to rung n taking 1 or 2 rungs per step, and some rungs are broken and cannot be stepped on. Return the number of distinct ways to reach the top.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


A warehouse associate climbs a ladder from rung 0 to rung n taking 1 or 2 rungs per step, and some rungs are broken and cannot be stepped on. Return the number of distinct ways to reach the top.

A safety-flavored warm-up in the style of Amazon phone screens. It checks the Fibonacci-style recurrence, base cases, and how blocked states zero out a DP cell.

What the Interviewer Expects
  • Define ways[i] as paths to land on rung i
  • Recurrence ways[i] = ways[i-1] + ways[i-2]
  • Set broken rungs to 0 ways
  • Roll to two variables
  • Mention modulo for large n
Key Topics to Cover
1D dynamic programming
counting paths
Fibonacci recurrence
blocked states
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 steps of 1, 2, or 3 are allowed?
  • Return the count modulo 1e9+7 for n up to 10^6.
  • How would you compute it for n = 10^18 with no broken rungs?
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: integer n and a list broken of rung indices. Rung 0 is the floor. Output: number of step sequences from 0 to n that never land on a broken rung....

High-Level Design

The last step into rung i came from i-1 or i-2, and those are disjoint sets of paths, so ways[i] = ways[i-1] + ways[i-2]. Base: ways[0] = 1 (the empty path) and ways[-1] = 0. A broken rung can n...


Submit Your Answer
Markdown supported