Challenge - 5 Problems
Climbing Stairs Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Recursive Climbing Stairs
What is the output of the following JavaScript code that counts ways to climb stairs recursively?
DSA Javascript
function climbStairs(n) {
if (n <= 2) return n;
return climbStairs(n - 1) + climbStairs(n - 2);
}
console.log(climbStairs(4));Attempts:
2 left
💡 Hint
Think about the number of ways to climb 3 and 2 stairs and add them.
✗ Incorrect
The function returns the sum of ways to climb n-1 and n-2 stairs. For n=4, ways = climbStairs(3) + climbStairs(2) = 3 + 2 = 5.
❓ Predict Output
intermediateOutput of Iterative Climbing Stairs
What is the output of this iterative JavaScript function that calculates ways to climb stairs?
DSA Javascript
function climbStairs(n) {
let a = 1, b = 1;
for (let i = 2; i <= n; i++) {
let temp = a + b;
a = b;
b = temp;
}
return b;
}
console.log(climbStairs(5));Attempts:
2 left
💡 Hint
This function uses Fibonacci sequence logic starting with 1,1.
✗ Incorrect
The function iteratively calculates Fibonacci numbers. For n=5, the output is 8.
🔧 Debug
advancedIdentify the Error in Memoized Climbing Stairs
What error does this JavaScript code produce when run?
DSA Javascript
function climbStairs(n, memo = {}) {
if (n <= 2) return n;
if (memo[n]) return memo[n];
memo[n] = climbStairs(n - 1, memo) + climbStairs(n - 2, memo);
return memo[n];
}
console.log(climbStairs('5'));Attempts:
2 left
💡 Hint
Check how the function handles string input for n.
✗ Incorrect
JavaScript converts '5' to number 5 in arithmetic operations, so the function works and outputs 8.
❓ Predict Output
advancedOutput of Climbing Stairs with Steps 1, 2, or 3
What is the output of this code that counts ways to climb stairs with steps of 1, 2, or 3?
DSA Javascript
function climbStairs(n) {
if (n === 0) return 1;
if (n < 0) return 0;
return climbStairs(n - 1) + climbStairs(n - 2) + climbStairs(n - 3);
}
console.log(climbStairs(4));Attempts:
2 left
💡 Hint
Count all ways to reach step 4 using 1, 2, or 3 steps.
✗ Incorrect
Ways to climb 4 steps with 1,2,3 steps are 7.
🧠 Conceptual
expertMinimum Steps to Climb Stairs with Variable Steps
Given an array of allowed steps [1, 3, 5], what is the minimum number of steps to climb 11 stairs? Choose the correct minimum count.
Attempts:
2 left
💡 Hint
Try combinations of 5, 3, and 1 steps to reach 11 with fewest moves.
✗ Incorrect
The minimum number of steps is 3, for example 5 + 3 + 3 or 5 + 5 + 1.
