Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to insert a character into the Trie node's children.
DSA Java
node.children[[1] - 'a'] = new TrieNode();
Attempts:
3 left
💡 Hint
Common Mistakes
Using loop index 'i' instead of character 'ch'.
Using variable 'index' which is undefined.
✗ Incorrect
We use 'ch' as the character to find the correct index in children array.
2fill in blank
mediumComplete the code to check if a prefix exists in the Trie.
DSA Java
if (node.children[[1] - 'a'] == null) return false;
Attempts:
3 left
💡 Hint
Common Mistakes
Using loop index 'i' instead of character 'ch'.
Using undefined variable 'index'.
✗ Incorrect
We check the child node corresponding to character 'ch'.
3fill in blank
hardFix the error in the code to mark the end of a word in the Trie.
DSA Java
node.[1] = true;Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names that do not exist in the TrieNode class.
Using 'end' or 'wordEnd' which are not standard.
✗ Incorrect
The standard boolean flag to mark word end is 'isEndOfWord'.
4fill in blank
hardFill both blanks to complete the Trie search method for a word.
DSA Java
for (char [1] : word.toCharArray()) { if (node.children[[2] - 'a'] == null) return false; node = node.children[[2] - 'a']; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for loop and index.
Using loop index 'i' which is not defined in this loop.
✗ Incorrect
The loop variable and index use the same character 'ch' to access children.
5fill in blank
hardFill all three blanks to create a map comprehension that counts characters in a string.
DSA Java
Map<Character, Integer> counts = new HashMap<>(); for (char [1] : word.toCharArray()) { counts.put([2], counts.getOrDefault([3], 0) + 1); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names causing errors.
Using undefined variables in map methods.
✗ Incorrect
Use 'ch' consistently to count each character's frequency in the map.
