0
0
DSA Typescriptprogramming~20 mins

Climbing Stairs Problem in DSA Typescript - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Climbing Stairs Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of climbingStairs(4) with simple recursion
What is the output of the following TypeScript function call: climbingStairs(4)?
DSA Typescript
function climbingStairs(n: number): number {
  if (n <= 2) return n;
  return climbingStairs(n - 1) + climbingStairs(n - 2);
}

console.log(climbingStairs(4));
A7
B6
C4
D5
Attempts:
2 left
💡 Hint
Think about how many ways to climb 3 steps and 2 steps add up for 4 steps.
Predict Output
intermediate
2:00remaining
Output of climbingStairs(5) with memoization
What is the output of the following TypeScript code when calling climbingStairs(5)?
DSA Typescript
function climbingStairs(n: number, memo: Record<number, number> = {}): number {
  if (n <= 2) return n;
  if (memo[n] !== undefined) return memo[n];
  memo[n] = climbingStairs(n - 1, memo) + climbingStairs(n - 2, memo);
  return memo[n];
}

console.log(climbingStairs(5));
A8
B7
C5
D10
Attempts:
2 left
💡 Hint
Use the relation climbingStairs(n) = climbingStairs(n-1) + climbingStairs(n-2) with memoization.
🔧 Debug
advanced
2:00remaining
Identify the error in climbingStairs iterative solution
What error will the following TypeScript code produce when calling climbingStairs(3)?
DSA Typescript
function climbingStairs(n: number): number {
  let a = 1, b = 2;
  for (let i = 3; i <= n; i++) {
    let c = a + b;
    a = b;
    b = c;
  }
  return b;
}

console.log(climbingStairs(3));
AReturns 2
BRuntime error: undefined variable
CReturns 3
DReturns 5
Attempts:
2 left
💡 Hint
Check initial values and loop start index carefully.
🧠 Conceptual
advanced
1:00remaining
Number of ways to climb 0 steps
According to the climbing stairs problem, how many ways are there to climb 0 steps?
A2 ways
B1 way (do nothing)
CUndefined
D0 ways
Attempts:
2 left
💡 Hint
Think about the base case for no steps.
🚀 Application
expert
3:00remaining
Minimum number of jumps to reach the top
Given an array where each element represents the maximum jump length from that position, what is the minimum number of jumps to reach the last index? For example, for [2,3,1,1,4], what is the minimum jumps needed?
A2
B3
C4
D1
Attempts:
2 left
💡 Hint
Try to jump to the farthest reachable index at each step.