Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to insert a character into the children map of the Trie node.
DSA Rust
self.children.insert([1], TrieNode::new());Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase letters instead of lowercase.
Inserting a character not present in the word.
✗ Incorrect
The character 'a' is inserted as a key in the children map to create a new TrieNode.
2fill in blank
mediumComplete the code to check if the current character exists in the children map during search.
DSA Rust
if !node.children.contains_key(&[1]) { return false; }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for a character not in the word.
Using a character without referencing it correctly.
✗ Incorrect
We check if the character 'a' exists in the children map to continue the search.
3fill in blank
hardFix the error in the code to move to the next Trie node during search.
DSA Rust
node = node.children.get(&[1]).unwrap();Attempts:
3 left
💡 Hint
Common Mistakes
Using a character not present in the children map.
Not unwrapping the Option returned by get().
✗ Incorrect
We get the child node corresponding to character 'a' to continue traversal.
4fill in blank
hardFill both blanks to complete the loop that inserts each character of the word into the Trie.
DSA Rust
for ch in word.[1]() { node = node.children.entry(ch).or_insert([2]); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using iter() on a string which returns bytes, not chars.
Inserting a Vec instead of a TrieNode.
✗ Incorrect
We iterate over each character using chars() and insert new TrieNode if missing.
5fill in blank
hardFill all three blanks to complete the search function that returns true if the word exists in the Trie.
DSA Rust
let mut node = &self.root; for ch in word.[1]() { if !node.children.[2](&ch) { return false; } node = node.children.[3](&ch).unwrap(); } node.is_end_of_word
Attempts:
3 left
💡 Hint
Common Mistakes
Using iter() which returns bytes, not characters.
Using get() without checking contains_key() first.
Not unwrapping the Option returned by get().
✗ Incorrect
We iterate over characters, check if child exists with contains_key, then get the child node.
