Implement Trie
Updated
Problem 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 Onsite Interview questions
- Design Search Autocomplete SystemPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Candy Crush Grid Matching and GravityPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Topological Sort with Secondary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Most Frequent Call Stack Per ThreadPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Count and Score Distinct Hat AssignmentsONSITE INTERVIEW · Seen Sep 2026
- Rate Limiter Sliding Window With Per-Entity LimitsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Most Frequent Call Path in Interleaved LogsONSITE INTERVIEW · Seen Aug 2026
- Grid Pathfinding with Obstacles (DFS)PHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026
- Maximize Distance to Closest Person — Return the SeatONSITE INTERVIEW · Seen Jun 2026
- Sliding Window: Target Containment and Most-Repeated WindowONSITE INTERVIEW · Seen Jun 2026
Similar questions at other companies
- Word Dictionary with Wildcard FindAmazon · ONSITE INTERVIEW
- Implement a TrieMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Add Word and Suffix SearchAnduril · ONSITE INTERVIEWAnduril interview questions
- Trie: Add and Search WordsAdobe · ONSITE INTERVIEWAdobe interview questions
- In-Memory Directory and File OperationsSquarepoint Capital · ONSITE INTERVIEWSquarepoint Capital interview questions
- File System PathsCapital One · ONSITE INTERVIEWCapital One interview questions
- Implement TrieBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Trie With Insert, Search and Prefix CheckExpedia · ONSITE INTERVIEWExpedia interview questions
- Design File SystemGoogle · PHONE SCREENGoogle interview questions
- Implement TrieOptiver · PHONE SCREENOptiver interview questions
Interview reports that mention this question
Roblox interview experiences
- Roblox New Grad Early OA Tasks: 10 Experiences (Part 7 of 7)
- Roblox New Grad Engineer Rounds: 13 Experiences (Part 6 of 7)
- Roblox New Grad HackerRank OA: 18 Experiences (Part 5 of 7)
- Roblox New Grad CodeSignal Finals: 23 Experiences (Part 4 of 7)
- Roblox New Grad Coding Rounds: 23 Experiences (Part 2 of 7)