Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Word Exists in Trie

Triesmedium

Implement `trieHasWord(words, word)` that builds a trie from `words` and returns whether `word` is a complete stored word.

Sample tests

Input: trieHasWord(["cat","car"], "car")
Output: true
Input: trieHasWord(["cat"], "ca")
Output: false

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Returning true for a prefix that is not a complete word.

Learning resources

  • Wikipedia: Trie
Approach & explanation (try first)

A trie stores words character by character; the end flag distinguishes a full word from a prefix. Lookup is O(word length).

Loading...
⌘/Ctrl + Enter

Run your code to see results.