Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for space ' ' instead of null character.
Using double quotes instead of single quotes for characters.
✗ Incorrect
The string ends with the null character '\0' in C, so checking str[0] == '\0' means the string is empty.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using sizeof which returns size of pointer, not string length.
Using non-existent functions like length or count.
✗ Incorrect
In C, the function strlen() returns the length of a string excluding the null character.
3fill in blank
hardFix 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'
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.
✗ Incorrect
strncmp compares the first n characters; n should be length of the dictionary word to match substring correctly.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different lengths for comparison and dp update.
Using string length or indices instead of dictionary word length.
✗ Incorrect
We compare substring length with dictionary word length and update dp at position i + length of dict word.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in loop parts.
Incorrect loop condition or increment.
✗ Incorrect
The outer loop uses variable i from 0 to len-1, incrementing i each time.