Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the DP table with zeros.
DSA C++
int dp[n+1] = {0}; for (int i = 0; i <= n; i++) { dp[i] = [1]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 causes incorrect base values.
Using -1 can cause wrong results in summations.
✗ Incorrect
We initialize each element of the dp array to 0 to start the bottom-up calculation.
2fill in blank
mediumComplete the code to fill the DP table for the Fibonacci sequence.
DSA C++
dp[0] = 0; dp[1] = 1; for (int i = 2; i <= n; i++) { dp[i] = dp[i-1] [1] dp[i-2]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication instead of addition.
Using subtraction causes wrong sequence.
✗ Incorrect
Fibonacci numbers are the sum of the two previous numbers.
3fill in blank
hardFix the error in the code to correctly compute the minimum coin count for amount 'amt'.
DSA C++
for (int i = 1; i <= amt; i++) { dp[i] = INT_MAX; for (int coin : coins) { if (i - coin >= 0 && dp[i - coin] != INT_MAX) { dp[i] = std::min(dp[i], dp[i - coin] [1] 1); } } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction causes wrong coin count.
Using multiplication or division is incorrect here.
✗ Incorrect
We add 1 to the previous minimum to count the current coin.
4fill in blank
hardFill both blanks to complete the code for counting ways to make change.
DSA C++
dp[0] = 1; for (int coin : coins) { for (int i = [1]; i <= amount; i++) { dp[i] = dp[i] [2] dp[i - coin]; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Starting loop from 0 causes invalid indices.
Using '-=' instead of '+=' causes wrong counts.
✗ Incorrect
We start from coin value and add ways from dp[i - coin].
5fill in blank
hardComplete the code to complete the code for Longest Common Subsequence (LCS) tabulation.
DSA C++
for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { if (s1[i-1] == s2[j-1]) { dp[i][j] = dp[i-1][j-1] [1] 1; } else { dp[i][j] = std::max(dp[i-1][j], dp[i][j-1]) ; } } }
Attempts:
3 left
💡 Hint
Common Mistakes
Subtracting or multiplying instead of adding 1.
Adding or subtracting in else case causes wrong results.
✗ Incorrect
Add 1 when characters match; else take max without change.
