Code RoomStaircase paths avoiding broken steps
MediumPrep Room Coding #674

Staircase paths avoiding broken steps

CodingAlgorithms & data structuresEntry–Mid~12 min

A staircase has steps numbered 1 through n, and you start on the ground (position 0). Each move climbs 1 or 2 steps. Some steps are broken and cannot be landed on; their numbers are given in the list broken (all values are between 1 and n, no duplicates). Return the number of distinct ways to reach step n exactly without ever landing on a broken step. If step n itself is broken, return 0.

Implement
count_safe_paths(n: int, broken: list[int]) → int
Examples
in[5,[]]out8
in[5,[3]]out2
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 12 min
InputExpectedGot
[5,[]]8not run yetsample
[5,[3]]2not run yetsample