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 TypeScript code that initializes a Trie node and prints its children keys?
DSA Typescript
class TrieNode { children: Map<string, TrieNode>; isEndOfWord: boolean; constructor() { this.children = new Map(); this.isEndOfWord = false; } } const node = new TrieNode(); console.log(Array.from(node.children.keys()));
Attempts:
2 left
💡 Hint
Think about what keys exist in a newly created empty Map.
✗ Incorrect
A new TrieNode has an empty Map for children, so no keys exist. Converting keys to an array results in an empty array [].
❓ Predict Output
intermediate2:00remaining
Trie Node Children After Insert
After inserting a child node with key 'a' into a TrieNode's children Map, what is the output of printing the keys?
DSA Typescript
class TrieNode { children: Map<string, TrieNode>; isEndOfWord: boolean; constructor() { this.children = new Map(); this.isEndOfWord = false; } } const node = new TrieNode(); node.children.set('a', new TrieNode()); console.log(Array.from(node.children.keys()));
Attempts:
2 left
💡 Hint
Check what key was added to the Map.
✗ Incorrect
The key 'a' was added to the children Map, so printing keys shows ['a'].
🔧 Debug
advanced2:00remaining
Identify the Error in TrieNode Constructor
What error will this TypeScript code produce when creating a TrieNode instance?
DSA Typescript
class TrieNode { children: Map<string, TrieNode>; isEndOfWord: boolean; constructor() { this.children = {}; this.children.set('a', new TrieNode()); this.isEndOfWord = false; } } const node = new TrieNode();
Attempts:
2 left
💡 Hint
Check the type assigned to children and how Map methods are used.
✗ Incorrect
Assigning {} to children means it's a plain object, not a Map. Calling Map methods like set on it causes TypeError.
🧠 Conceptual
advanced1:30remaining
Purpose of isEndOfWord in TrieNode
What is the main purpose of the isEndOfWord boolean property in a TrieNode?
Attempts:
2 left
💡 Hint
Think about how a Trie distinguishes complete words from prefixes.
✗ Incorrect
isEndOfWord marks nodes that complete a valid word, differentiating them from nodes that are just prefixes.
❓ Predict Output
expert3:00remaining
Final Trie Structure After Multiple Insertions
Given the following code inserting words into a Trie, what is the output of printing the root node's children keys?
DSA Typescript
class TrieNode { children: Map<string, TrieNode>; isEndOfWord: boolean; constructor() { this.children = new Map(); this.isEndOfWord = false; } } class Trie { root: TrieNode; constructor() { this.root = new TrieNode(); } insert(word: string) { let current = this.root; for (const char of word) { if (!current.children.has(char)) { current.children.set(char, new TrieNode()); } current = current.children.get(char)!; } current.isEndOfWord = true; } } const trie = new Trie(); trie.insert('cat'); trie.insert('car'); trie.insert('dog'); console.log(Array.from(trie.root.children.keys()));
Attempts:
2 left
💡 Hint
The root's children keys are the first letters of inserted words.
✗ Incorrect
Words 'cat' and 'car' start with 'c', 'dog' starts with 'd', so root children keys are ['c', 'd'].