KV Store with Nested Transactions
Implement an in-memory key-value store that supports nested transactions. Commands are executed in order, one command per line.
Supported commands are:
SET <key> <value>GET <key>DELETE <key>BEGINROLLBACKCOMMIT
GET returns the current value of a key, or NULL if it does not exist. ROLLBACK and COMMIT print NO TRANSACTION when there is no active transaction.
Return the lines that would be printed while processing the command batch.
Complete the function runNestedTransactions in the editor below.
runNestedTransactions has the following parameter:
String[] commands: the command batch, one command per element
Returns
String[]: the output lines produced by the batch in order.
1Example 1
After setting a to 10, GET a prints that value.
2Example 2
The inner transaction deletes a, so the first GET prints NULL. After rolling back the inner transaction, a becomes 20 again. Committing keeps that value permanent.
Constraints
Limits and guarantees your solution can rely on.
1 <= commands.length <= 200000- Keys and values are non-empty strings without spaces.
- Transactions may be nested arbitrarily deeply.
- A near-linear total runtime is expected for large command batches.