The Find Number of Ways to Reach the K-th Stair interview question is a dynamic climbing problem with unique rules. You start at stair 1. In each step, you can either:
Amazon uses this Find Number of Ways coding problem to test a candidate's ability to handle state-based recursion and Memoization. The jumps grow exponentially, meaning the state space is actually quite small despite the complex rules. It evaluations your ability to identify the necessary components of a state (current stair, jump power, and previous move type).
This problem uses Recursive DP with Memoization or Combinatorics.
solve(current_stair, jump_power, can_go_down)
can_go_down: Boolean to prevent two consecutive "down" moves.can_go_down, try solve(current_stair - 1, jump_power, false).solve(current_stair + 2^jump_power, jump_power + 1, true).current_stair exceeds by more than 1 (because you can only go down once to reach ).Target . Start at 1.
When jumps are exponential (), always check if the problem can be solved with Memoization. The "exponential" part usually means you will hit the target or overshoot it very quickly, limiting the number of recursive calls.