Implement Trie
medium
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.
Constraints
1. 1 <= word.length, prefix.length <= 2000 2. word and prefix consist only of lowercase English letters.
Format
Input
Input is managed for you
Output
Output is managed for you
Example
Sample Input
insert apple
search apple
search app
startsWith app
insert app
search app
Sample Output
true
false
true
true