easy1-D Dynamic ProgrammingAdobeAppleAmazon
Staircase Hopper
A courier counts the number of unique paths up a straight staircase while taking either 1 or 2 steps at a time.
You are climbing a staircase that takes n steps. Each step you can climb 1 or 2 stairs. In how many distinct ways can you reach the top?
Choose approach
?
01
12
2?
3?
4?
5?
6i
1/6
Narrationstep 1 of 6
Base: dp[1]=1, dp[2]=2.
Variables
n=6
How to think about it
- Each step comes from either a 1-hop or 2-hop predecessor.
- Fibonacci identity: F(n+1).
Edge cases to catch in interview
- n = 1 -> 1.
- n = 2 -> 2.
Examples
Example 1
3{"n":3}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed