Challenge - 5 Problems
Trie Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Trie Node Initialization
What is the output of the following code that initializes a Trie node and prints its children keys?
DSA Python
class TrieNode: def __init__(self): self.children = {} self.is_end_of_word = False node = TrieNode() print(list(node.children.keys()))
Attempts:
2 left
💡 Hint
Think about what keys exist in the children dictionary right after initialization.
✗ Incorrect
The children dictionary is empty when a TrieNode is created, so printing its keys shows an empty list.
❓ Predict Output
intermediateCheck is_end_of_word Flag After Initialization
What is the value of
is_end_of_word immediately after creating a new TrieNode?DSA Python
class TrieNode: def __init__(self): self.children = {} self.is_end_of_word = False node = TrieNode() print(node.is_end_of_word)
Attempts:
2 left
💡 Hint
Look at the default value assigned to is_end_of_word in the constructor.
✗ Incorrect
The flag is_end_of_word is set to False when the node is created.
🔧 Debug
advancedIdentify the Error in TrieNode Initialization
What error will this code raise when trying to create a TrieNode?
DSA Python
class TrieNode: def __init__(self): self.children = [] self.is_end_of_word = False node = TrieNode() print(node.children['a'])
Attempts:
2 left
💡 Hint
Check the type of children and how it is accessed.
✗ Incorrect
The children attribute is a list, but the code tries to access it with a string key, causing a TypeError.
❓ Predict Output
advancedChildren Dictionary After Adding a Child Node
What is the output after adding a child node for character 'c' to the children dictionary of a TrieNode?
DSA Python
class TrieNode: def __init__(self): self.children = {} self.is_end_of_word = False node = TrieNode() node.children['c'] = TrieNode() print(list(node.children.keys()))
Attempts:
2 left
💡 Hint
Think about what keys exist after adding a child node with key 'c'.
✗ Incorrect
After adding a child node with key 'c', the children dictionary contains one key: 'c'.
🧠 Conceptual
expertWhy Use a Dictionary for Children in TrieNode?
Which is the main reason to use a dictionary for the children attribute in a TrieNode instead of a list?
Attempts:
2 left
💡 Hint
Consider how you find a child node for a given character quickly.
✗ Incorrect
Dictionaries provide O(1) average time complexity for key lookup, which is ideal for checking if a child node exists for a character.
