Count Ways Up a Data Center Ladder With Broken Rungs

Last updated: November 29, 2026

Quick Overview

A technician climbs a ladder with n rungs taking one or two rungs per step, but some rungs are broken and cannot be stepped on. Count the ways to reach the top rung modulo 1,000,000,007.

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

0

0

0 solved


A technician climbs a ladder with n rungs taking one or two rungs per step, but some rungs are broken and cannot be stepped on. Count the ways to reach the top rung modulo 1,000,000,007.

A gentle twist on stair climbing that Google phone screeners use to check whether you can add a constraint to a known recurrence rather than recite it. They watch for correct handling of a broken top rung and of the base case.

What the Interviewer Expects
  • Define ways[i] as the count of ways to stand on rung i
  • Force ways[i] = 0 for broken rungs
  • Combine from i - 1 and i - 2 otherwise
  • Handle the case where the top rung itself is broken
  • Use rolling variables and a modulus
Key Topics to Cover
1D dynamic programming
Stair climbing
Constraints on states
Modular counting
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
  • Allow steps of 1, 2 or 3 rungs.
  • Steps of size 2 cost extra effort; count ways with at most m big steps.
  • Return the number of ways that avoid stepping on any two consecutive rungs.
  • What if broken rungs are given as a very large sorted list with n up to 10^12?
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 >= 0 and a set broken of rung indices in 1..n. The technician starts on the ground (rung 0, never broken) and must finish standing on rung n. Each move goes up 1 or 2 rungs and mu...

High-Level Design

Let ways[i] be the number of move sequences that end standing on rung i. If rung i is broken, ways[i] = 0 because no sequence may stand there. Otherwise the last move came from rung i - 1 or i - 2...


Submit Your Answer
Markdown supported