Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the DP array with zeros.
DSA C#
int[] dp = new int[n + 1]; for (int i = 0; i <= n; i++) { dp[i] = [1]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing with 1 causes incorrect base values.
Using -1 may cause wrong results in summation problems.
✗ Incorrect
The DP array should be initialized with zeros to represent base cases before filling in values.
2fill in blank
mediumComplete the code to fill the DP array using the bottom-up approach.
DSA C#
for (int i = 1; i <= n; i++) { dp[i] = dp[i - 1] + [1]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Adding i instead of 1 changes the count incorrectly.
Adding dp[i] causes self-reference and errors.
✗ Incorrect
We add 1 to the previous dp value to count ways or steps incrementally.
3fill in blank
hardFix the error in the DP update step to avoid index out of range.
DSA C#
for (int i = 1; i <= n; i++) { if (i - 2 >= 0) { [1] } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using dp[i] + dp[i-1] causes double counting.
Assigning dp[i] = dp[i-2] loses dp[i-1] contribution.
✗ Incorrect
The correct update sums dp[i-1] and dp[i-2] to build the current dp[i] value.
4fill in blank
hardFill both blanks to complete the nested loop for a 2D DP table.
DSA C#
for (int i = 1; i <= m; i++) { for (int j = 1; j <= [1]; j++) { dp[i, j] = dp[i - 1, j] + dp[i, [2]]; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using m instead of n for inner loop limit.
Using i-1 instead of j-1 for dp index.
✗ Incorrect
The inner loop runs up to n, and dp[i, j] depends on dp[i, j-1].
5fill in blank
hardFill all three blanks to complete the DP dictionary comprehension equivalent in C#.
DSA C#
var result = new Dictionary<string, int>(); foreach (var word in words) { result[[1]] = word.[2]; if (result[[3]] == 0) { result[[3]] = 1; } else { result[[3]] += 1; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using Count instead of Length for string length.
Using inconsistent keys for dictionary access.
✗ Incorrect
We use the word as key, Length property for length, and word again as key to update count.
