Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the input string is empty.
DSA Java
if (s.[1]()) { return true; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using length() instead of isEmpty()
Using equals() which compares strings
Using substring() which extracts parts of the string
✗ Incorrect
The method isEmpty() returns true if the string has zero length, which means it's empty.
2fill in blank
mediumComplete the code to check if the string starts with a dictionary word.
DSA Java
if (s.[1](word)) { // proceed }
Attempts:
3 left
💡 Hint
Common Mistakes
Using contains() which checks anywhere in the string
Using endsWith() which checks the end of the string
Using equals() which checks full string equality
✗ Incorrect
startsWith(word) checks if the string s begins with the substring word.
3fill in blank
hardFix the error in the recursive call to check the remaining substring.
DSA Java
if (wordBreak(s.[1](word.length()), wordDict)) { return true; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using subString() with uppercase 'S' causes a compile error
Using substr() or slice() which are not Java String methods
✗ Incorrect
substring() is the correct Java method to get a part of the string starting from an index.
4fill in blank
hardFill both blanks to create a loop that checks each word in the dictionary.
DSA Java
for (String [1] : [2]) { // check word }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 's' which is the input string, not the dictionary
Using 'dict' which is not defined in the code
✗ Incorrect
The loop variable is 'word' and the collection to iterate is 'wordDict'.
5fill in blank
hardFill all three blanks to build a memoization map that stores results.
DSA Java
Map<String, Boolean> [1] = new HashMap<>(); if ([2].containsKey(s)) { return [3].get(s); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names causing errors
Using 'cache' inconsistently
✗ Incorrect
The memoization map is named 'memo' and is used to check and get stored results.
