Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to insert a character node into the children map.
DSA Rust
node.children.[1];Attempts:
3 left
💡 Hint
Common Mistakes
Using push or add which are not methods of HashMap.
Using TrieNode::default() if new() is defined for node creation.
✗ Incorrect
The insert method adds a key-value pair to the children HashMap. Using TrieNode::new() creates a new node.
2fill in blank
mediumComplete the code to check if a character exists in the children map.
DSA Rust
if node.children.contains_key(&[1]) {
Attempts:
3 left
💡 Hint
Common Mistakes
Using node or value instead of the character key.
Not passing a reference to the key.
✗ Incorrect
We check if the children map has the character key ch using contains_key(&ch).
3fill in blank
hardFix the error in the code to mark the end of a word.
DSA Rust
node.is_end_of_word = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Setting the flag to false or zero which means not end of word.
Using None which is not a boolean.
✗ Incorrect
To mark the end of a word, set is_end_of_word to true.
4fill in blank
hardFill both blanks to traverse or create a child node for each character.
DSA Rust
node = node.children.entry([1]).or_insert_with([2]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using insert instead of or_insert_with.
Using default instead of new if new is defined.
✗ Incorrect
We use entry(ch) to get or create the child node, and or_insert_with(TrieNode::new) to insert a new node if missing.
5fill in blank
hardFill all three blanks to complete the insert function for the Trie.
DSA Rust
for [1] in word.chars() { node = node.children.entry([2]).or_insert_with([3]); } node.is_end_of_word = true;
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Using default instead of new for node creation.
✗ Incorrect
We iterate over characters with c, use entry(c) to access children, and or_insert_with(TrieNode::new) to create nodes.
