Challenge - 5 Problems
Trie Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Trie Node Initialization
What is the output of the following JavaScript code that initializes a Trie node and prints its properties?
DSA Javascript
class TrieNode {
constructor() {
this.children = {};
this.isEndOfWord = false;
}
}
const node = new TrieNode();
console.log(JSON.stringify(node));Attempts:
2 left
💡 Hint
Look at how the children property is initialized and the default value of isEndOfWord.
✗ Incorrect
The TrieNode constructor initializes children as an empty object and isEndOfWord as false. So the JSON string reflects these values.
❓ Predict Output
intermediate2:00remaining
Trie Node Children Property Type
What will be the output of this code snippet that checks the type of the children property in a Trie node?
DSA Javascript
class TrieNode {
constructor() {
this.children = {};
this.isEndOfWord = false;
}
}
const node = new TrieNode();
console.log(typeof node.children);Attempts:
2 left
💡 Hint
Remember what type JavaScript returns for objects and arrays.
✗ Incorrect
In JavaScript, typeof an object literal returns 'object'. Arrays are also objects but typeof returns 'object' for them too, not 'array'.
❓ Predict Output
advanced2:00remaining
Adding a Child Node to Trie Node
What is the output after adding a child node with key 'a' to the children of a Trie node and printing the children keys?
DSA Javascript
class TrieNode { constructor() { this.children = {}; this.isEndOfWord = false; } } const node = new TrieNode(); node.children['a'] = new TrieNode(); console.log(Object.keys(node.children));
Attempts:
2 left
💡 Hint
Check what keys are present in the children object after adding a new child.
✗ Incorrect
After adding a child node with key 'a', the children object has one key 'a'. Object.keys returns an array of keys.
🧠 Conceptual
advanced1:30remaining
Purpose of isEndOfWord in Trie Node
What is the main purpose of the isEndOfWord property in a Trie node?
Attempts:
2 left
💡 Hint
Think about how a Trie distinguishes between prefixes and complete words.
✗ Incorrect
The isEndOfWord boolean marks if the path to this node forms a complete word stored in the Trie.
❓ Predict Output
expert2:30remaining
Output After Multiple Insertions in Trie Node
Given the following code that inserts characters into a Trie node's children, what is the output of printing the children keys of the root node?
DSA Javascript
class TrieNode { constructor() { this.children = {}; this.isEndOfWord = false; } } const root = new TrieNode(); const word = 'cat'; for (const char of word) { if (!root.children[char]) { root.children[char] = new TrieNode(); } } console.log(Object.keys(root.children));
Attempts:
2 left
💡 Hint
Each character is added as a separate child key if it does not exist.
✗ Incorrect
The loop adds each character as a separate key in the root's children. So keys are 'c', 'a', and 't'.