← 返回 openai 的题目列表KV Store with Serialization (Basic Operations)
类型:online_judge
Problem: Implement a KV Store with Serialization (Basic Operations)
Implement an in-memory key-value store that serializes/deserializes values before storing/transmitting them (i.e., value encode/decode). Provide the following basic APIs.
API Requirements
Implement a KVStore that supports:
put(key, value): insert or overwrite the value for a key.
get(key): return the value for a key; if absent, return empty (e.g., null / None / NOT_FOUND).
delete(key): delete a key; no-op if missing.
serialize(value) / deserialize(blob): serialize and deserialize values.
Serialization Requirements (you may design a simple protocol)
The serialized output must be a string or byte array.
Deserialization must faithfully restore the original value.
Must handle special characters and edge cases (e.g., delimiters inside values, empty strings).
Constraints
Single-machine in-memory only (no distributed consistency needed).
Assume keys are strings.
Values are strings (or a small set of types, but include type info in serialization).
What to Provide
Core data structures and time complexities.
At least 5 test cases covering overwrite, delete, empty/special characters, and round-trip correctness.
Scale
Up to 200,000 operations.
Up to 10,000 characters per key/value.
Example
Input
put a hello
get a
Output
hello