Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new TrieNode in the insert method.
DSA Java
if (node.children[c - 'a'] == null) { node.children[c - 'a'] = new [1](); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using String or other types instead of TrieNode.
Forgetting to create a new node before assigning.
✗ Incorrect
We create a new TrieNode object to represent the child node for the character.
2fill in blank
mediumComplete the code to mark the end of a word in the insert method.
DSA Java
node.[1] = true;Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect field names like isWord or wordEnd.
Not marking the end of the word at all.
✗ Incorrect
The boolean field isEnd marks that this node represents the end of a word.
3fill in blank
hardFix the error in the loop that iterates over characters in the insert method.
DSA Java
for (int i = 0; i [1] word.length(); i++) { char c = word.charAt(i); // rest of code }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' causes index out of bounds error.
Using '>' or '>=' causes the loop to never run.
✗ Incorrect
The loop should run while i is less than word.length() to avoid index out of bounds.
4fill in blank
hardFill both blanks to correctly update the node pointer and access children array.
DSA Java
node = node.children[[1] - [2]];
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'z' instead of 'a' for subtraction.
Using loop index i instead of character c.
✗ Incorrect
We subtract 'a' from character c to get the correct index in children array.
5fill in blank
hardFill all three blanks to complete the insert method's loop and marking end of word.
DSA Java
for (int [1] = 0; i [2] word.length(); [3]++) { char c = word.charAt(i); if (node.children[c - 'a'] == null) { node.children[c - 'a'] = new TrieNode(); } node = node.children[c - 'a']; } node.isEnd = true;
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong loop variable names.
Using wrong loop condition operators.
Forgetting to increment the loop variable.
✗ Incorrect
The loop uses variable i starting at 0, runs while i < word.length(), and increments i each time.
