Problem · String
Implement Trie
Learn this problemProblem statement
Implement the behavior of a prefix tree, also known as a trie.
A trie supports three operations:
insert(word): insertwordinto the trie.search(word): return whetherwordwas previously inserted as a complete word.startsWith(prefix): return whether at least one previously inserted word starts withprefix.
For this FastPrep draft, operations are provided as arrays. operations[i] is one of "insert", "search", or "startsWith", and values[i] is the word or prefix for that operation. Return the boolean results for only the search and startsWith operations, in the order they occur. insert operations do not produce output.
Function
trieOperations(operations: String[], values: String[]) → boolean[]Examples
Example 1
operations = ["insert", "search", "search", "startsWith", "insert", "search"]values = ["dog", "dog", "do", "do", "do", "do"]return = [true, false, true, true]After inserting dog, search(dog) is true, search(do) is false, and startsWith(do) is true. After inserting do, search(do) becomes true.
Example 2
operations = ["search", "insert", "startsWith", "search"]values = ["a", "abc", "ab", "abc"]return = [false, true, true]The first search happens before abc is inserted. After insertion, ab is a valid prefix and abc is a stored word.
Constraints
operations.length == values.lengthoperations[i]is"insert","search", or"startsWith".1 <= values[i].length <= 1000values[i]contains only lowercase English letters.
More Roblox problems
- Most Frequent Call Stack Per ThreadPHONE SCREEN · Seen Jul 2026
- Break a PalindromeOA · Seen Jun 2026
- Candy Crush Grid Matching and GravityPHONE SCREEN · Seen Jun 2026
- Closest Binary Search Tree Value — Base PracticePHONE SCREEN · Seen Jun 2026
- Design Search Autocomplete SystemPHONE SCREEN · Seen Jun 2026
- Grid Pathfinding with Obstacles (DFS)PHONE SCREEN · Seen Jun 2026
- Maximize Distance to Closest Person — Return the SeatONSITE INTERVIEW · Seen Jun 2026
- Maximum Number of Balls in a BoxPHONE SCREEN · Seen Jun 2026