← 返回 openai 的题目列表Persistent Key-Value Store
类型:online_judge
Persistent Key-Value Store
Design and implement a persistent key-value store.
Functional requirements
Support the following operations:
put(key, value): insert or overwrite a key-value pair
get(key): return the value for key; if missing, return empty/NOT_FOUND
delete(key): delete key; ignore if it does not exist
Persistence: after process restart / re-initialization, previously written data must still be readable (recover from disk).
I/O format (pick one as specified by interviewer)
Command stream (stdin): one command per line, e.g.
PUT <key> <value>
GET <key>
DEL <key>
Print one line for each GET.
API: implement put/get/delete, and provide open(path) / close() or a constructor that takes a data file path.
Constraints and edge cases (clarify with interviewer if unspecified)
Keys/values are strings or byte sequences.
Number of operations can be large; aim for reasonable time complexity.
You may use an append-only log and/or snapshots to support recovery.
Example
Input:
PUT a 1
PUT b hello
GET a
DEL a
GET a
GET b
Output:
1
NOT_FOUND
hello
Suggested scale assumptions
Operations N up to 1e5
Key/value length: 1 ~ 1e3
Example
Input
PUT a 1
PUT b hello
GET a
DEL a
GET a
GET b
Output
1
NOT_FOUND
hello