Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to insert a word into the Trie node children.
DSA Javascript
node.children[[1]] = new TrieNode(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the whole word as a key instead of a single character.
Using the node itself as a key.
✗ Incorrect
Each character (char) of the word is used as a key in the children map to create or access the next Trie node.
2fill in blank
mediumComplete the code to check if the current node has a child for the character.
DSA Javascript
if (!node.children.hasOwnProperty([1])) { return false; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for the whole word instead of a character.
Using an incorrect variable like index.
✗ Incorrect
We check if the children object has the current character as a key to continue traversal.
3fill in blank
hardFix the error in the search function to correctly return if a word exists in the Trie.
DSA Javascript
return node.isEndOfWord === [1];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning false instead of true for end of word.
Returning null or undefined which are incorrect.
✗ Incorrect
The search should return true only if the node marks the end of a word.
4fill in blank
hardFill both blanks to complete the prefix search function that returns true if any word starts with the prefix.
DSA Javascript
for (let [1] = 0; [1] < prefix.length; [1]++) { let [2] = prefix[[1]]; if (!node.children.hasOwnProperty([2])) return false; node = node.children[[2]]; } return true;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same variable name for both index and character.
Using incorrect variable names that don't match the code.
✗ Incorrect
The loop index variable is 'i' and the current character is 'char' used to check children.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.
DSA Javascript
const result = { [1]: [2] for (const [3] of words) if [2] > 3 }; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect variable names or values in the comprehension.
Confusing keys and values.
✗ Incorrect
We map each word (key) to its length (value) for words longer than 3 characters.