Problem · String
Add Word and Suffix Search
Learn this problemProblem statement
Process matching arrays operations and values from left to right. Each operation is one of:
add: store the lowercase word in the correspondingvaluesentry. Adding a duplicate word does not change future answers.search: appendtrueto the result when at least one stored word ends with the complete queried suffix; otherwise appendfalse.
An empty suffix matches exactly when at least one word has already been added. Return one Boolean for every search operation, in operation order.
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]Both initial words end in ple, no stored word ends in xyz, and the later word happy ends in py.
Example 2
operations = ["search","add","search","add","search"]values = ["","code","","code","de"]return = [false,true,true]The first empty-suffix query occurs before any add. After code is added, an empty suffix matches. Adding the duplicate changes nothing, and de still matches.
Constraints
operations.length == values.length.1 <= operations.length <= 200000.- Every operation is
"add"or"search". - Added words are non-empty lowercase English strings; suffixes are lowercase English strings and may be empty.
- The sum of all word and suffix lengths is at most
500000.