← 返回 nvidia 的题目列表Design an OOP Key-Value Store with set, get, and setAll
类型:online_judge
Problem: Design an OOP Key-Value Store with set, get, and setAll
Design a key-value store KVStore that supports:
set(key, value): set key to value.
get(key): return the value for key, or null if the key does not exist.
setAll(value): set the value of all currently stored keys to value.
Implement it in an OOP style and state the time complexity of each operation.
Requirements
Keys are hashable (string or integer).
Make setAll efficient; avoid iterating over all keys on each setAll if possible.
Example
Operations:
set("a", 1)
set("b", 2)
get("a") -> 1
setAll(9)
get("a") -> 9
set("a", 7)
get("a") -> 7
get("b") -> 9
Example
Input
8
set a 1
set b 2
get a
setAll 9
get a
set a 7
get a
get b
Output
1
9
7
9