Netflix questions

Versioned Key-Value Store

NetflixOnsiteHard

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.

Part 1: Put and get by time

Implement:

  • put(key, value, ts) stores value as the version of key at time ts. If key already has a version at exactly ts, the new value replaces it. Returns nothing.
  • get(key, ts) returns the value of the version of key with the greatest timestamp that is at most ts, or None if there is no such version.
  1. Example 1
    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"]

    Why: 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.

Constraints

  • 1 <= len(operations) <= 2 * 10^4
  • -10^9 <= ts <= 10^9
  • 1 <= len(key) <= 10
  • 1 <= len(value) <= 10
  • key and value are made of lowercase letters and digits
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question
Versioned Key-Value Store: Netflix interview question | LoopCoach