← 返回 databricks 的题目列表Design an In-Memory KV Store with a Hit Counter
类型:online_judge
Design an in-memory Key-Value store that also maintains a hit counter.
Requirements:
Support basic operations:
put(key, value): insert/overwrite
get(key): read; if the key exists, increment that key's hit counter
delete(key): remove the key
Support querying the hit counter:
hits(key): return how many successful get hits this key has had (define behavior if key does not exist)
State complexity goals (e.g., average O(1) per operation).
(Optional) Discuss concurrency/atomicity approaches (locks, RW locks, sharding, atomics).
Suggested scale: up to 1e6 keys.
Provide at least 5 test cases covering:
basic put/get
overwrite
behavior after delete
missing get
correctness of hit counters
Example
Input
put(a,1); get(a); hits(a)
Output
get(a)=1; hits(a)=1