FastPrepVersioned Key-Value Store with Commits
Problems/Versioned Key-Value Store with Commits

Versioned Key-Value Store with Commits

Otter.ai logoOtter.ai● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report directly asks for set/get/delete followed by GitHub-like commit and rollover behavior. Interpreting rollover as rollback to an immutable numbered commit yields an executable store matching the recognizable task at about 91%.

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.

More Otter.ai problems

  • Minimum Operations to Make Every Array Element OnePHONE SCREEN · Seen Oct 2026
  • Rotting OrangesONSITE INTERVIEW · Seen Aug 2026
All Otter.ai interview questionsSee Otter.ai hiring insights
Saved
class Solution {
    public String[] versionedStore(String[] operations) {
        // Write your solution here.
    }
}
Checking account…