Climbing Stairs
Real-world version: Rung Ladder ClimbsThe statement here is our own: the same inputs, outputs and technique.
A maintenance robot waits on the ground under a ladder whose rungs are numbered 1 through n, counting upward from the bottom. Each pull of its winch raises the robot by exactly one rung or by exactly two rungs, and it never lowers itself. The job is finished the moment the robot stands on rung n, and it must not overshoot that rung.
Two climbs are counted separately when their lists of pull sizes differ at some position, so a one-rung pull followed by a two-rung pull is a different climb from a two-rung pull followed by a one-rung pull.
Return how many climbs finish on rung n.
Examples
Example 1
- Input
- n = 1
- Output
- 1
A single one-rung pull is the only way up, since a two-rung pull would carry the robot past the top.
Example 2
- Input
- n = 5
- Output
- 8
Writing pulls in order: 1+1+1+1+1, 1+1+1+2, 1+1+2+1, 1+2+1+1, 2+1+1+1, 1+2+2, 2+1+2 and 2+2+1.
Example 3
- Input
- n = 7
- Output
- 21
The climbs that end on rung 7 split into those whose last pull was one rung (13 of them, ending from rung 6) and those whose last pull was two rungs (8 of them, ending from rung 5).
Constraints
- 1 <= n <= 45
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def ladder_climbs(n: int) -> int:public int ladderClimbs(int n)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Fibonacci NumberReal-world version: Cascade Register ReadingEasy
- N-th Tribonacci NumberReal-world version: Three-Day Dispatch LadderEasy
- Different Ways to Add ParenthesesReal-world version: Every Value a Sum Can Be Grouped IntoMedium
- Count Sequences to KReal-world version: Selections of Throws Scoring Exactly kHard