Algorithms Playbook
← All problems
MediumTries →Similar to: Implement Trie (Prefix Tree)

An index of word prefixes

Problem

Design a class with insert(word), search(word) (is exactly this word stored?) and startsWith(prefix) (does any stored word begin with this prefix?). All inputs are lowercase letters.

Examples

Input: insert("car"); search("car"); search("ca"); startsWith("ca")

Output: true, false, true

Hints

    Try it first. Every hint reveals a bit more.

    Solution