In-Memory Key-Value Store Operations
Problem statement
Process a finite ordered sequence of operations on an in-memory key-value store. The store starts empty, keys are strings, and values are signed integers.
["SET", key, value]stores or overwrites the integer value underkeyand produces no output.["GET", key]producesVALUE:followed by the current integer, orNULLwhen the key is absent.["DELETE", key]removes the key when present and producestrueif a key was removed orfalseotherwise.
Return the outputs from GET and DELETE operations in operation order.
Function
runKeyValueStore(operations: String[][]) → String[]Examples
Example 1
operations = [["SET","a","1"],["GET","a"],["SET","a","-2"],["GET","a"],["DELETE","a"],["GET","a"],["DELETE","a"]]return = ["VALUE:1","VALUE:-2","true","NULL","false"]The second SET overwrites a. The first deletion succeeds; afterward a is absent and another deletion returns false.
Example 2
operations = [["GET","missing"],["SET","x","0"],["SET","y","2147483647"],["GET","y"],["DELETE","x"],["GET","x"]]return = ["NULL","VALUE:2147483647","true","NULL"]A missing lookup returns NULL. Keys are independent, and deleting x does not change y.
Example 3
operations = [["SET","only","-2147483648"]]return = []A sequence containing only SET operations produces no output.
Constraints
1 <= operations.length <= 100000.- Every operation is well formed and has exactly the fields described above.
- Keys contain from
1through50printable ASCII characters. - Every
SETvalue is a signed 32-bit integer written in base 10.