FunctionRacerProblemsRace

Broken Stairs

EasyDynamic programmingPython, JavaScript, TypeScript, Java, C++

You climb from step 0 to step n, moving one or two steps at a time. The steps listed in broken cannot be stepped on. Return the number of ways to reach step n. If step n itself is broken, the answer is 0.

Example 1

n 5
broken [2]
returns 2

Two ways: 1+2+2 (steps 1, 3, 5) and 1+2+1+1 (steps 1, 3, 4, 5).

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Dynamic programming problems