Medium · Trees

Trie (prefix tree)

Given a list of lowercase words to insert into a trie and a query word, return true if the query was inserted as a complete word and false otherwise — a word that is only a prefix of an inserted word does not count.

Examples

Example 1

{
  "insert": ["cat", "car", "can", "dog"],
  "search": "car"
}

Output: true

Example 2

{
  "insert": ["to", "tea", "ten", "i", "in"],
  "search": "ten"
}

Output: true

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Trees problems