Trie (Prefix Tree)/Medium

Implement Trie (Prefix Tree)PRO PASS

Time: O(L) per opSpace: O(N * L)

Step 1: Setup & Initialization - Implement Trie

Traverse node edges character by character.

Array Elements & Pointers
10
[0]
20
[1]
30
[2]
40
[3]
50
[4]
Live Variables & Invariants
status:Initialized
pattern:Implement Trie
Step 1 / 333%
Solution Code
1
class Trie {
2
  root = {};
3
  insert(word: string) {
4
    let node: any = this.root;
5
    for (const c of word) { node[c] = node[c] || {}; node = node[c]; }
6
    node.isEnd = true;
7
  }
8
}

Custom Test Case Runner

Input your custom values and visualize step-by-step trace

Quick Presets:

AI DSA Coach

Contextual Tutor for Implement Trie (Prefix Tree)

Hello! I am your AI DSA Tutor for **Implement Trie (Prefix Tree)** (Trie (Prefix Tree)). Ask me anything about this algorithm, time complexity, or request a step hint!