Dashboard
LC #208

Implement Trie (Prefix Tree)

Pattern · ?AmazonGoogleMetaMicrosoftBloomberg

Problem

Implement a trie with insert, search (exact), and startsWith (prefix) operations.

Constraints

  • 1 ≤ word.length, prefix.length ≤ 2000
  • Lowercase English letters only
  • At most 3 × 10⁴ calls total

Example

Input
insert("apple"), search("apple"), search("app"), startsWith("app"), insert("app"), search("app")
Output
true, false, true, true
Why
"apple" inserted → search exact match returns true; "app" not inserted yet → false; startsWith always checks prefix

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗