0
0
DSA Cprogramming~10 mins

Climbing Stairs Problem in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to return the base case for 1 step.

DSA C
if (n == 1) return [1];
Drag options to blanks, or click blank then click option'
A2
B0
Cn
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 0 instead of 1 for the base case.
Returning n which is unnecessary here.
2fill in blank
medium

Complete the code to return the base case for 2 steps.

DSA C
if (n == 2) return [1];
Drag options to blanks, or click blank then click option'
A1
B3
C2
Dn
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 1 instead of 2 for the base case.
Returning n which is 2 but not explained.
3fill in blank
hard

Fix the error in the recursive return statement to correctly sum the ways.

DSA C
return climbStairs(n [1] 1) + climbStairs(n [1] 2);
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of - causing incorrect recursion.
Using * or / which are not valid here.
4fill in blank
hard

Fill both blanks to create a loop that fills dp array for climbing stairs.

DSA C
for (int i = 3; i <= n; i++) {
    dp[i] = dp[i [1] 1] + dp[i [2] 2];
}
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition or multiplication instead of subtraction in indices.
Mixing operators causing wrong dp indexing.
5fill in blank
hard

Fill all three blanks to initialize dp array and return the final result.

DSA C
int dp[n+1];
dp[1] = [1];
dp[2] = [2];
return dp[[3]];
Drag options to blanks, or click blank then click option'
A1
B2
Cn
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Returning dp[0] or dp[1] instead of dp[n].
Incorrect base values for dp[1] or dp[2].