logo
Interview
    Interview Guide
    Coding Problems List
Sponsored: Coursera
Problems

Implement Trie (Prefix Tree)

Problem

Implement a trie with insert, search, and startsWith methods.

Example

insert("lintcode")
search("code") // return false
startsWith("lint") // return true
startsWith("linterror") // return false
insert("linterror")
search("lintcode") // return true
startsWith("linterror") // return true

Note

You may assume that all inputs are consist of lowercase letters a-z.

Solution

A typical Trie problem.

Related Problems

Online Judge