Implement in-memory KV store with serialization
Company: OpenAI
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates skills in designing and implementing an in-memory key-value store with serialization, testing data structure design, API design (set/get/serialize/deserialize), serialization format selection, type fidelity for common Python types, and robust error handling.
Read the full OpenAI Software Engineer interview experience this question came from
Constraints
- 0 <= len(operations) <= 10^4
- Store keys and all nested dict keys must be strings
- Supported stored values are int, finite float, str, list, and dict with recursive nesting
- The total size of all values and serialized blobs processed is at most 2 * 10^5
Examples
Input: [('set', 'count', 5), ('set', 'info', {'name': 'Ada', 'scores': [1, 2.5]}), ('serialize',), ('deserialize', '{"count":5,"info":{"name":"Ada","scores":[1,2.5]}}'), ('get', 'info')]
Expected Output: [True, True, '{"count":5,"info":{"name":"Ada","scores":[1,2.5]}}', True, {'name': 'Ada', 'scores': [1, 2.5]}]
Explanation: Two values are stored, the whole store is serialized to deterministic JSON, deserialized back, and the nested object is retrieved unchanged.
Input: [('set', 'x', [1, 2, 3]), ('get', 'missing'), ('deserialize', '{"x":[1,2,3]'), ('get', 'x')]
Expected Output: [True, None, False, [1, 2, 3]]
Explanation: Getting a missing key returns None. The malformed JSON blob fails to deserialize, so the previous store remains intact.
Hints
- Use a normal dictionary for the live store, and write one recursive helper that validates whether a value can be safely serialized without losing type information.
- Make serialization deterministic by sorting keys and removing extra whitespace, so exact string comparisons in tests are stable.