Magicsheet logo

Find Number of Ways to Reach the K-th Stair

Hard
25%
Updated 8/1/2025

Find Number of Ways to Reach the K-th Stair

What is this problem about?

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:

  1. Go down 1 stair (cannot be done twice in a row).
  2. Jump up 2j2^j stairs (where jj is the number of jumps made so far). You need to find the total number of ways to reach stair kk.

Why is this asked in interviews?

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).

Algorithmic pattern used

This problem uses Recursive DP with Memoization or Combinatorics.

  1. State: solve(current_stair, jump_power, can_go_down)
    • can_go_down: Boolean to prevent two consecutive "down" moves.
  2. Transitions:
    • If can_go_down, try solve(current_stair - 1, jump_power, false).
    • Always try solve(current_stair + 2^jump_power, jump_power + 1, true).
  3. Base Case: Since jump power grows as 2j2^j, you can stop when current_stair exceeds kk by more than 1 (because you can only go down once to reach kk).

Example explanation

Target k=1k=1. Start at 1.

  • Initial: at 1. Count = 1 (we are already there).
  • Move 1: Go down to 0. At 0, must jump 20=12^0=1. Reach 1. Count += 1.
  • Move 2: Jump 20=12^0=1. Reach 2. At 2, can go down to 1. Count += 1. This explores different sequences of jumps and downs to find all paths to 1.

Common mistakes candidates make

  • Infinite Recursion: Failing to define a proper bound for the jump power or current stair.
  • Ignoring consecutive rule: Forgetting that you cannot go down twice in a row.
  • Missing paths: Not realizing that you can reach kk multiple times in different branches of the recursion.

Interview preparation tip

When jumps are exponential (2j2^j), 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.

Similar Questions