AlgoMaster Logo
AlgoMasterImplement Object Versioninghard

Implement Object Versioning

hard

Object versioning preserves earlier writes and represents deletion with a new delete marker rather than destroying history.

Design a VersionedObjectStore:

  • put(key, value) creates a version and returns its globally increasing ID, starting at 1.
  • deleteObject(key) creates a delete-marker version and returns its ID, even when the key is absent.
  • get(key) returns the latest value or "NOT_FOUND" when absent or hidden by a marker.
  • getVersion(key, versionId) returns that historical value only when the version belongs to key and is not a marker.
  • restore(key, versionId) copies a valid historical value into a new version and returns the new ID; otherwise it returns -1.

Values never equal "NOT_FOUND".

Example 1:
Example 2:

Constraints

  • Keys and values contain 1 to 100 printable ASCII characters.
  • Values are not "NOT_FOUND".
  • At most 10^4 operations are performed.
Hints

Loading...
CallReturns
new VersionedObjectStore()null
put("photo", "v1")1
put("photo", "v2")2
get("photo")"v2"
getVersion("photo", 1)"v1"

Both writes remain addressable, while the second version is latest.

Run checks these cases. Submit also runs a larger hidden set.