Answer: SQUADSTACK Hiring Challenge | Interview Question | On-Campus OA (2023)

Answer · Posted Jun 2026

Approach Let: dp[i] = number of ways to reach stair i For stair i, the last jump could be: 1 step from i-1 2 steps from i-2 3 steps from i-3 Therefore: Base cases: f(1) = 1 f(2) = 2 f(3) = 4 Strategy Handle base cases. Maintain the last three values. Compute current value using: previous one-step ways previous two-step ways previous three-step ways Update variables. Return answer. Java Code class Solution { public int climbStairs(int n) { if ...

The full answer & interview discussion are available to premium members.

Log in Create a free account