Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 0 instead of 1 for the base case.
Returning n which is unnecessary here.
✗ Incorrect
When there is only 1 step, there is exactly 1 way to climb it.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 1 instead of 2 for the base case.
Returning n which is 2 but not explained.
✗ Incorrect
For 2 steps, you can climb as (1+1) or (2), so 2 ways.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of - causing incorrect recursion.
Using * or / which are not valid here.
✗ Incorrect
We subtract 1 and 2 from n to find ways to climb remaining steps.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition or multiplication instead of subtraction in indices.
Mixing operators causing wrong dp indexing.
✗ Incorrect
We subtract 1 and 2 to get previous dp values to sum.
5fill in blank
hardFill 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'
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].
✗ Incorrect
dp[1] = 1 way, dp[2] = 2 ways, return dp[n] for total ways.