Versioned Key-Value Store

Asked at NetflixOnsite

Reported by the problem's creator, not verified

Build an in-memory key-value store that keeps every version of every key. Keys and values are strings, and each write carries an integer timestamp. Writes may arrive out of timestamp order, and the same timestamp can be written more than once.

Each test drives one VersionedStore instance through a sequence of method calls and checks every return value.

Examples

  1. Example 1

    Input: init = [], operations = [["put",["campaignA","v1",10]],["put",["campaignA","v2",20]],["get",["campaignA",15]],["get",["campaignA",20]],["get",["campaignA",5]],["get",["other",15]],["put",["k","a",5]],["put",["k","b",5]],["get",["k",5]],["get",["k",99]]]

    Output: [null,null,"v1","v2",null,null,null,null,"b","b"]

    Explanation: At time 15 the latest version at or before 15 is v1 (written at 10). At 20 it is v2, and at 5 there is none. The second write to k at time 5 replaces the first.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.