Transactional Key-Value Store
SnowflakePhone screenMedium
Implement an in-memory key-value store as a class TxStore. Keys are lowercase strings and values are integers. Each test creates one TxStore and calls its methods in order; the result records every call's return value, including None. You build the store in stages: each part adds behavior on top of the previous parts, and all earlier behavior must keep working.
Part 1: Basic operations
Implement three methods on TxStore:
put(key, value)storesvalueunderkey, replacing any previous value. ReturnsNone.get(key)returns the value stored underkey, orNoneif no value is stored.delete(key)removeskeyand returnsTrueif it was present, otherwise returnsFalse.
- Example 1
- init
[]- operations
[["put",["a",5]],["get",["a"]],["get",["b"]],["delete",["a"]],["get",["a"]],["delete",["a"]]]- Output
[null,5,null,true,null,false]
Why: put(a,5) stores 5; get(a) returns 5; get(b) finds nothing; delete(a) removes the key and returns True; get(a) is then None, and the second delete(a) finds nothing and returns False.
Constraints
1 <= len(operations) <= 10^41 <= len(key) <= 10'a' <= key[i] <= 'z'-10^9 <= value <= 10^9