Key-Value Store
DatabricksOnsiteMedium
Design a string-to-string store that also tracks how often each key is read. Each test drives a single KVStore instance through a sequence of method calls and checks every return value.
Part 1: Put and get
Implement two methods.
put(key, value)storesvalueunderkey, replacing any earlier value, and returns"OK".get(key)returns the value stored underkey, or"NULL"ifkeywas never stored. The empty string is a real value, so a key stored with""returns"", not"NULL".
- Example 1
- init
[]- operations
[["get",["a"]],["put",["a","x"]],["get",["a"]],["put",["a","y"]],["get",["a"]],["put",["b",""]],["get",["b"]],["get",["c"]]]- Output
["NULL","OK","x","OK","y","OK","","NULL"]
Why: A get on a missing key returns NULL. After put(a, x) the next get returns x, and overwriting a with y makes the following get return y. An empty string is a real value, so get(b) returns it rather than NULL.
Constraints
1 <= len(key) <= 100 <= len(value) <= 10'a' <= key[i] <= 'z'1 <= len(operations) <= 10^4
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.