Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the maximum length variable to zero.
DSA C
int maxLen = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing maxLen to 1 causes incorrect results when no common substring exists.
Using NULL is invalid for integer initialization.
✗ Incorrect
The maximum length of the common substring starts at zero before checking any characters.
2fill in blank
mediumComplete the code to update the DP table when characters match.
DSA C
if (s1[i - 1] == s2[j - 1]) { dp[i][j] = dp[i - 1][j - 1] [1] 1; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication causes wrong DP values.
Dividing dp values is not meaningful here.
✗ Incorrect
When characters match, the length extends by 1 from the previous diagonal value.
3fill in blank
hardFix the error in updating the maximum length after DP update.
DSA C
if (dp[i][j] [1] maxLen) { maxLen = dp[i][j]; endIndex = i - 1; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' updates maxLen incorrectly.
Using '==' or '!=' does not update maxLen properly.
✗ Incorrect
We update maxLen only if the current dp value is greater than maxLen.
4fill in blank
hardFill both blanks to correctly initialize the DP table with zeros.
DSA C
for (int i = 0; i <= len1; i++) { dp[i][[1]] = 0; } for (int j = 0; j <= len2; j++) { dp[[2]][j] = 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using len1 or len2 as indices causes out-of-bound errors.
Not initializing base cases leads to incorrect DP results.
✗ Incorrect
The first row and first column of the DP table are initialized to zero to handle base cases.
5fill in blank
hardFill all three blanks to correctly extract the longest common substring from s1.
DSA C
int start = endIndex - [1] + 1; char result[[2] + 1]; for (int i = 0; i < [3]; i++) { result[i] = s1[start + i]; } result[[2]] = '\0';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using endIndex instead of maxLen for length causes wrong substring size.
Not adding 1 for null terminator causes string errors.
✗ Incorrect
We use maxLen to calculate the start index, allocate result size, and copy characters.