KV Store with Rollback
Design and implement an in-memory key-value store that supports version checkpoints and rollback.
Supported operations are:
PUT <key> <value>GET <key>CHECKPOINTROLLBACK <version>
CHECKPOINT creates a new snapshot version. ROLLBACK version restores the store to the exact state at that checkpoint.
Return the lines printed by the command sequence. Only GET outputs are required in the examples below.
Complete the function runVersionedKvStore in the editor below.
runVersionedKvStore has the following parameter:
String[] operations: the operations to execute in order
Returns
String[]: the output lines produced by the batch.
1Example 1
The first GET sees the updated value 2. After rolling back to the first checkpoint, a returns to 1.
2Example 2
Rolling back to version 1 restores the snapshot created after y was added but before x was changed to 7.
Constraints
Limits and guarantees your solution can rely on.
- Checkpoint ids are increasing integers.
- After a rollback, the full store state must match the target checkpoint exactly.
- Invalid rollback behavior should be handled consistently by the implementation.