Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to insert a character into the Trie node's children dictionary.
DSA C#
node.Children[[1]] = new TrieNode();Attempts:
3 left
💡 Hint
Common Mistakes
Using the index i instead of the character.
Using the whole word instead of a single character.
✗ Incorrect
We use the current character word[i] as the key to insert into the children dictionary.
2fill in blank
mediumComplete the code to check if the Trie node has a child for the current character.
DSA C#
if (!node.Children.ContainsKey([1]))
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for the whole word instead of a single character.
Using the index i instead of the character.
✗ Incorrect
We check if the children dictionary contains the current character word[i] as a key.
3fill in blank
hardFix the error in the code to mark the end of a word in the Trie.
DSA C#
node.IsEndOfWord = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Setting IsEndOfWord to false or null.
Using numeric values instead of boolean.
✗ Incorrect
We set IsEndOfWord to true to mark that the current node represents the end of a valid word.
4fill in blank
hardFill both blanks to complete the code that searches for a word in the Trie.
DSA C#
for (int i = 0; i < word.Length; i++) { if (!node.Children.ContainsKey([1])) { return false; } node = node.Children[[2]]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using the whole word or index instead of the character.
Using different keys for check and access.
✗ Incorrect
We use word[i] to check and access the child node for each character in the word.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
DSA C#
var result = words.Where([3] => [2] > 3).ToDictionary([3] => [1], [3] => [2]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using length as a variable without defining it.
Mixing key and value positions.
✗ Incorrect
We map each word (key) to its length (value) for words longer than 3 characters.
