Mutable Record Store with Error Results
Problem statement
Process commands over string records keyed by id:
INSERT id valuecreates a missing record.UPDATE id valuechanges an existing record.REMOVE iddeletes an existing record.GET idreads an existing value.
Every successful mutation emits OK. A duplicate insert or any missing-id update, remove, or get emits ERROR. GET otherwise emits the value. Return all results in command order.
Function
recordStore(operations: String[]) → String[]Examples
Example 1
operations = ["INSERT a one","GET a","UPDATE a two","GET a","REMOVE a","GET a"]return = ["OK","one","OK","two","OK","ERROR"]The record moves through insert, update, removal, and missing read.
Example 2
operations = ["INSERT x 1","INSERT x 2","GET x"]return = ["OK","ERROR","1"]A duplicate insert does not overwrite.
Example 3
operations = ["UPDATE q 9","REMOVE q"]return = ["ERROR","ERROR"]Both operations require an existing record.
Constraints
1 <= operations.length <= 10^5.- Ids and values are nonempty strings without spaces.
- Commands are valid and use only the four documented operations.