0
0
DSA Cprogramming~10 mins

Longest Common Substring 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 initialize the maximum length variable to zero.

DSA C
int maxLen = [1];
Drag options to blanks, or click blank then click option'
A1
B0
C-1
DNULL
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.
2fill in blank
medium

Complete 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'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication causes wrong DP values.
Dividing dp values is not meaningful here.
3fill in blank
hard

Fix 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'
A<
B!=
C==
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' updates maxLen incorrectly.
Using '==' or '!=' does not update maxLen properly.
4fill in blank
hard

Fill 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'
A0
Blen1
Dlen2
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.
5fill in blank
hard

Fill 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'
AmaxLen
DendIndex
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.