Hash Strategies Target: 15s
Trie insert walks/creates nodes per character, marks end. Search is identical but checks existence instead of creating.
class TrieNode:
def __init__(self):
self.children = {}
self.is_end = False
def insert(root, word):
node = root
for ch in word:
if ch not in node.children:
node.children[ch] = TrieNode()
node = node.children[ch]
node.is_end = True
Type it from memory. Go.