A trie or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings Implement the Trie class: 1. Trie(): Initializes the trie object. 2. void insert(String word): Inserts the string word into the trie. 3. boolean search(String word): Returns true if the string word is in the trie (i.e., was inserted before), and false otherwise. 4. boolean startsWith(String prefix): Returns true if there is a previously inserted string word that has the prefix prefix, and false otherwise.
1. 1 <= word.length, prefix.length <= 2000 2. word and prefix consist only of lowercase English letters.
Input is managed for you
Output is managed for you
insert apple search apple search app startsWith app insert app search app
true false true true