Panda Guru LogoPanda
Guru

Amazon SDE1 ( Jan-Jun 2025) Intern

Round 1

Questions: The coding question was titled "Game of Stairs" where the player, Ron, must move from the 1st stair to the M-th stair using a set of rules:

For input: 1, output: 4 distinct ways to reach.

Candidate's Approach

To solve the problem, I would use dynamic programming. The idea is to maintain an array dp where dp[i] represents the number of ways to reach stair i. The transitions would be as follows:

  • For each stair i, I can reach it from i - 2^j (where j is a non-negative integer such that 2^j <= i) by pressing the Up button.
  • Additionally, I can reach stair i from i - 1 by pressing the Down button, but only if the last move was not a Down move.

The base case would be dp[1] = 1 since there is one way to be on the first stair (starting point).

The final answer would be dp[M].

Interviewer's Feedback

No feedback provided.