Back to course home
0% completed
Vote For New Content
Implement Trie (Prefix Tree) (medium)
Problem Statement
Design and implement a Trie (also known as a Prefix Tree). A trie is a tree-like data structure that stores a dynamic set of strings, and is particularly useful for searching for words with a given prefix.
Implement the Solution class:
- Solution()Initializes the object.
- void insert(word)Inserts- wordinto the trie, making it available for future searches.
- bool search(word)Checks if the word exists in the trie.
- bool startsWith(word)Checks if any word in the trie starts with the given prefix.
Examples
- Example 1:
- Input:
 
.....
.....
.....
Like the course? Get enrolled and start learning!