Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the current character exists in the children dictionary.
DSA C#
if (!node.children.ContainsKey([1])) { return false; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using the whole word instead of a single character.
Using the index i directly instead of word[i].
✗ Incorrect
We check if the current character word[i] exists as a key in the children dictionary.
2fill in blank
mediumComplete the code to move to the next node in the Trie for the current character.
DSA C#
node = node.children[[1]];Attempts:
3 left
💡 Hint
Common Mistakes
Using the index i instead of the character word[i].
Using the whole word as key.
✗ Incorrect
We update node to the child node corresponding to the current character word[i].
3fill in blank
hardFix the error in the return statement to correctly check if the word ends here.
DSA C#
return node.[1];
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names like isEnd or endOfWord.
Returning the wrong property causing incorrect search results.
✗ Incorrect
The boolean property isWord indicates if the current node marks the end of a valid word.
4fill in blank
hardFill both blanks to complete the for loop that iterates over each character in the word.
DSA C#
for (int [1] = 0; [2] < word.Length; [1]++) { // loop body }
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in initialization and condition.
Using variable names not matching the loop body.
✗ Incorrect
The loop variable i is used consistently for initialization and condition check.
5fill in blank
hardFill all three blanks to complete the search method for the Trie.
DSA C#
public bool Search(string word)
{
TrieNode node = root;
for (int [1] = 0; [2] < word.Length; [1]++)
{
if (!node.children.ContainsKey(word[[3]]))
return false;
node = node.children[word[[3]]];
}
return node.isWord;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables for loop and indexing causing errors.
Using variables not declared in the loop.
✗ Incorrect
The loop variable i is used consistently for iteration and indexing characters in the word.
