Versioned Key-Value Store with Commits
Reported by candidates from Otter.ai's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Otter.ai reported this one in September 2026, and it looks like a toy until you hit ROLLBACK. It's a versioned key-value store, and the whole question hinges on one data structure choice: a hash map for the working state plus a list of saved snapshots. If you've got an Otter.ai OA coming up, this is a design-flavored problem dressed as string parsing. The logic is short, but the snapshot semantics trip people up. Know the shape before you open the editor. And if your mind goes blank mid-assessment, StealthCoder runs invisibly on your desktop and can hand you the structure in real time.
The problem
Process commands for an in-memory string key-value store. SET key value writes a value. GET key emits its value or NULL. DELETE key removes the key if present. COMMIT saves the current state as the next zero-based version and emits that version id. ROLLBACK versionId restores that saved state and emits OK. Saved versions remain available, and later writes form a new working branch. Return outputs from GET, COMMIT, and ROLLBACK commands in command order. Function versionedStore(operations: String[]) → String[] Examples Example 1 operations = ["SET a one","GET a","COMMIT","SET a two","GET a","ROLLBACK 0","GET a"] return = ["one","0","two","OK","one"] Version 0 stores a=one; rolling back restores it. Example 2 operations = ["GET missing","SET x 1","DELETE x","GET x"] return = ["NULL","NULL"] Missing and deleted keys both read as NULL. Example 3 operations = ["SET x 1","COMMIT","SET y 2","COMMIT","ROLLBACK 0","GET y","ROLLBACK 1","GET y"] return = ["0","1","OK","NULL","OK","2"] Earlier and later committed snapshots remain independently addressable. Constraints 1 <= operations.length <= 10^4. Keys and values are nonempty strings without spaces. Every ROLLBACK names an existing version.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Keep a current hash map and a list of snapshots. SET and DELETE mutate the current map. GET reads it, returning NULL if the key is missing. COMMIT copies the current map into the snapshot list and emits the index, which is just the list size before the append. ROLLBACK copies the saved snapshot back into the current map, so later writes never corrupt it. The pitfall is aliasing. If you store a reference instead of a copy, edits after a commit silently rewrite history, and Example 3 breaks. Copy on COMMIT and copy on ROLLBACK. With up to 10^4 operations, full copies are fine, so don't over-engineer persistent structures. Also note that only GET, COMMIT, and ROLLBACK produce output. SET and DELETE stay silent. Split each command on spaces and you're done. If you freeze on the copy semantics, StealthCoder is the hedge during the live OA.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Versioned Key-Value Store with Commits cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Otter.ai's OA.
Otter.ai reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Versioned Key-Value Store with Commits FAQ
What's the trick in the Otter.ai versioned key-value store problem?+
Deep copy the map. COMMIT stores a copy of the working state, and ROLLBACK loads a copy of a snapshot back. If you share references, later SET calls mutate saved versions and your outputs go wrong on the multi-commit examples.
Do I need a persistent data structure or can I just copy the map?+
Just copy. With at most 10^4 operations, copying the map on each COMMIT and ROLLBACK is fast enough for this problem. Persistent trees or delta logs are optimization you don't need here and they add bug risk.
What does ROLLBACK do to the saved versions?+
Nothing. Saved versions stay available, and the next COMMIT still gets the next version id, since ids keep incrementing from the snapshot list length. Writes after a rollback form a new working branch that starts from the restored state.
Which commands produce output?+
Only GET, COMMIT, and ROLLBACK. GET emits the value or NULL, COMMIT emits the new version id as a string, and ROLLBACK emits OK. SET and DELETE add nothing to the result array, so don't push empty strings.
How should I prepare for this in 48 hours?+
Write a small command-parser loop with a hash map and a snapshot list, then test it against the three examples by hand. Focus on the aliasing bug and on missing or deleted keys returning NULL. It's a short problem, so clean edge handling matters most.