Code Room
CodingMediumcod-g1472
Subject Dynamic programming 1dLevel Entry–Mid~12 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.