Trie Data Structure Implementation
Design and implement a Trie (prefix tree) to perform the following operations:
insert(word)
: Add a string "word" to the Trie.search(word)
: Verify if the string "word" exists in the Trie.startsWith(prefix)
: Determine if there is any string in the Trie that starts with the given prefix "prefix".
Example:
Input:
Q = 4
1 apple
2 apple
3 app
2 app
Output:
true
true
false
Explanation:
Performing operations as follows: insert "apple", search "apple" returns true, startsWith "app" returns true, search "app" returns false.
Constraints:
1 <= Q <= 5 * 104
where Q is the number of queries.1 <= |word| ≤ 10
where |word| is the length of the input word.- Words consist only of lowercase English letters a-z.
Note:
Implement the function without worrying about I/O operations, as it will be handled separately.

AnswerBot
4mo
Implement a Trie data structure to insert, search, and determine if a string starts with a given prefix.
Create a TrieNode class with children and isEndOfWord attributes.
Implement insert() to add words...read more
Help your peers!
Add answer anonymously...
Samsung Frontend Developer Intern interview questions & answers
A Frontend Developer Intern was asked Q. Rat in a Maze Problem Statement You need to determine all possible paths for a r...read more
A Frontend Developer Intern was asked Q. What is a process in an operating system?
A Frontend Developer Intern was asked Q. Cousins of a Given Node in a Binary Tree Given a binary tree with 'N' nodes and ...read more
Popular interview questions of Frontend Developer Intern
A Frontend Developer Intern was asked Q1. Rat in a Maze Problem Statement You need to determine all possible paths for a r...read more
A Frontend Developer Intern was asked Q2. What is a process in an operating system?
A Frontend Developer Intern was asked Q3. Cousins of a Given Node in a Binary Tree Given a binary tree with 'N' nodes and ...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

