Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the current character exists in the children of the node.
DSA Typescript
if (!node.children.has([1])) { return false; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the whole word instead of a single character.
Using the node variable instead of the character.
✗ Incorrect
We check if the current character 'char' exists in the children map of the node.
2fill in blank
mediumComplete the code to move to the next node in the trie for the current character.
DSA Typescript
node = node.children.get([1])!; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the whole word or index instead of the character.
Trying to get children with the node variable.
✗ Incorrect
We get the child node corresponding to the current character 'char' to continue traversal.
3fill in blank
hardFix the error in the return statement to check if the node marks the end of a word.
DSA Typescript
return node.[1];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names like 'isWord' or 'end'.
Returning the node itself instead of a boolean.
✗ Incorrect
The property 'isEndOfWord' indicates if the node marks the end of a valid word in the trie.
4fill in blank
hardFill both blanks to iterate over each character in the word and check the trie.
DSA Typescript
for (let [1] = 0; [2] < word.length; [2]++) { const char = word[[1]]; // rest of the code }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in initialization and condition.
Using variables not declared in the loop.
✗ Incorrect
The loop variable 'i' is used consistently to index characters in the word.
5fill in blank
hardFill all three blanks to complete the search function that returns true if the word exists in the trie.
DSA Typescript
function search(word: string): boolean {
let node = this.root;
for (let i = 0; i < word.length; i++) {
const char = word[[1]];
if (!node.children.has([2])) {
return false;
}
node = node.children.get([3])!;
}
return node.isEndOfWord;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'word' instead of 'char' to check children.
Using 'i' instead of 'char' to get children.
✗ Incorrect
We use 'i' to get the character from 'word', then check and get the child node using 'char'.