0
0
DSA Cprogramming~10 mins

Word Break Problem 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 check if the input string is empty.

DSA C
if (str[0] == [1]) {
    return 1;
}
Drag options to blanks, or click blank then click option'
A'\0'
B' '
C'a'
D'\n'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for space ' ' instead of null character.
Using double quotes instead of single quotes for characters.
2fill in blank
medium

Complete the code to get the length of the input string.

DSA C
int len = [1](str);
Drag options to blanks, or click blank then click option'
Asizeof
Bstrlen
Clength
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using sizeof which returns size of pointer, not string length.
Using non-existent functions like length or count.
3fill in blank
hard

Fix the error in the code that compares a substring with a dictionary word.

DSA C
if (strncmp(str + i, dict[j], [1]) == 0) {
    // substring matches dict word
}
Drag options to blanks, or click blank then click option'
Astrlen(str)
Bi
Cstrlen(dict[j])
Dj
Attempts:
3 left
💡 Hint
Common Mistakes
Using length of the whole string instead of dictionary word length.
Using index variables i or j as length.
4fill in blank
hard

Fill both blanks to correctly update the DP array and loop index.

DSA C
if (dp[i] && strncmp(str + i, dict[j], [1]) == 0) {
    dp[i + [2]] = 1;
}
Drag options to blanks, or click blank then click option'
Astrlen(dict[j])
Bstrlen(str)
Ci
Dj
Attempts:
3 left
💡 Hint
Common Mistakes
Using different lengths for comparison and dp update.
Using string length or indices instead of dictionary word length.
5fill in blank
hard

Fill all three blanks to complete the main loop for the word break problem.

DSA C
for (int [1] = 0; [2] < len; [3]++) {
    for (int j = 0; j < dictSize; j++) {
        if (dp[i] && strncmp(str + i, dict[j], strlen(dict[j])) == 0) {
            dp[i + strlen(dict[j])] = 1;
        }
    }
}
Drag options to blanks, or click blank then click option'
Ai
Blen
Dj
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in loop parts.
Incorrect loop condition or increment.