Note: In actual interview multi-threading discussion may also happen with this question.
RangedKeyValueStorage()
void set(String key, String value)
value for key.key already exists, its old value is replaced.String get(String key)
key.key does not exist, return an empty string "".List<String> getRange(String startKey, String endKey)
startKey ≤ key ≤ endKey."key,value".startKey and endKey do not need to exist in the storage.1 ≤ key.length() ≤ 1001 ≤ value.length() ≤ 1,0001 ≤ total number of method calls ≤ 100,000startKey ≤ endKeynull.RangedKeyValueStorage store = new RangedKeyValueStorage()store.set(key = "b", value = "banana")store.set(key = "a", value = "apple")store.get(key = "a")
"apple""a" exists with value "apple".RangedKeyValueStorage store = new RangedKeyValueStorage()store.set(key = "d", value = "dog")store.set(key = "b", value = "ball")store.set(key = "f", value = "fish")store.getRange(startKey = "b", endKey = "e")
["b,ball", "d,dog"]"b" and "d" are inside the range, and the output is sorted by key.RangedKeyValueStorage store = new RangedKeyValueStorage()store.set(key = "k1", value = "old")store.set(key = "k1", value = "new")store.get(key = "k1")
"new"set call replaces the previous value.RangedKeyValueStorage store = new RangedKeyValueStorage()store.set(key = "m", value = "moon")store.get(key = "x")store.getRange(startKey = "a", endKey = "c")
get: ""getRange: []"x" does not exist, and no stored key lies between "a" and "c".