Add Word and Suffix Search
Updated
Problem statement
You are given two arrays of the same length, operations and values. Go through them from left to right. Each operation is one of:
add: store the lowercase word at the same position invalues. Adding a word that is already stored does not change any later answer.search: the entry at the same position invaluesis a suffix to look for. Appendtrueto the result if at least one stored word ends with the whole suffix. Otherwise appendfalse.
An empty suffix matches when at least one word has already been added, and does not match otherwise. Return one Boolean for every search operation, in the order the operations appear.
Function
suffixSearch(operations: String[], values: String[]) → boolean[]Examples
Example 1
operations = ["add","add","search","search","add","search"]values = ["apple","maple","ple","xyz","happy","py"]return = [true,false,true]The first two words, apple and maple, both end in ple, so the first search gives true. No stored word ends in xyz, so the second search gives false. Then happy is added. It ends in py, so the last search gives true. The result is [true,false,true].
Example 2
operations = ["search","add","search","add","search"]values = ["","code","","code","de"]return = [false,true,true]The first search uses an empty suffix before any word is added, so it gives false. After code is added, the empty suffix matches, so the second search gives true. Adding code again changes nothing. The stored word code ends in de, so the last search gives true. The result is [false,true,true].
Constraints
operations.length == values.length.1 <= operations.length <= 200000.- Every operation is
"add"or"search". - Added words are non-empty strings of lowercase English letters. Suffixes are strings of lowercase English letters and may be empty.
- The sum of all word and suffix lengths is at most
500000.
More Anduril interview questions
- Binary Tree Preorder TraversalONSITE INTERVIEW · Seen Aug 2026
- Operator-First Array CalculatorONSITE INTERVIEW · Seen Aug 2026
- Daily TemperaturesONSITE INTERVIEW · Seen Jun 2024
- Highlighted Context WindowsONSITE INTERVIEW · Seen Jun 2024
- Pacific Atlantic Water FlowPHONE SCREEN · Seen Aug 2026
- Choose the Front Football TeamPHONE SCREEN · Seen May 2026
- Maximum Visible DronesPHONE SCREEN · Seen Jun 2024
- Build a Sorted Circular Singly Linked ListPHONE SCREEN · Seen Feb 2024
- Sparse Vector Dot ProductPHONE SCREEN · Seen Apr 2021
Similar questions at other companies
- Word Dictionary with Wildcard FindAmazon · ONSITE INTERVIEW
- Implement a TrieMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Trie: Add and Search WordsAdobe · ONSITE INTERVIEWAdobe interview questions
- Implement TrieRoblox · ONSITE INTERVIEWRoblox 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