PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/OpenAI

Implement a serializable key-value store

Last updated: Mar 29, 2026

Quick Overview

This question evaluates competency in implementing robust serialization and in-memory data structures, covering binary format design, handling arbitrary bytes and Unicode, correctness across edge cases (empty state, large keys/values, overwrites, deletions), input validation and failure recovery, complexity analysis, and unit testing.

  • Medium
  • OpenAI
  • Coding & Algorithms
  • Software Engineer

Implement a serializable key-value store

Company: OpenAI

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Implement in C++ an in-memory key-value store with: - put(key: string, value: string), get(key) -> optional<string>, erase(key). - serialize() -> vector<uint8_t> that encodes the entire store state. - deserialize(const vector<uint8_t>&) to restore an identical store state. Constraints: - Use only the provided helper byte I/O functions; do not use external libraries for serialization. - Choose a robust binary format (versioned, length-prefixed) that supports arbitrary bytes in keys/values and Unicode. - Ensure correctness for empty store, very large keys/values, duplicate overwrites, and deletions. - Validate input and handle malformed or truncated streams gracefully with clear error signaling. - Time/space complexity should be O(n) in the total serialized data size; support streaming-friendly encoding. - Provide unit tests and explain complexity, trade-offs (e.g., delimiter-escaped text vs. length-prefixed binary), and failure recovery.

Quick Answer: This question evaluates competency in implementing robust serialization and in-memory data structures, covering binary format design, handling arbitrary bytes and Unicode, correctness across edge cases (empty state, large keys/values, overwrites, deletions), input validation and failure recovery, complexity analysis, and unit testing.

Related Interview Questions

  • Simulate Infection Spread on a Grid - OpenAI (hard)
  • Implement Social Follow Recommendations - OpenAI (medium)
  • Build a Compose Rating Card - OpenAI (medium)
  • Generate Data Labeling Schedules - OpenAI (medium)
  • Convert IPv4 Ranges to CIDR Blocks - OpenAI (medium)
OpenAI logo
OpenAI
Jul 15, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
51
0

Implement in C++ an in-memory key-value store with:

  • put(key: string, value: string), get(key) -> optional <string> , erase(key).
  • serialize() -> vector<uint8_t> that encodes the entire store state.
  • deserialize(const vector<uint8_t>&) to restore an identical store state. Constraints:
  • Use only the provided helper byte I/O functions; do not use external libraries for serialization.
  • Choose a robust binary format (versioned, length-prefixed) that supports arbitrary bytes in keys/values and Unicode.
  • Ensure correctness for empty store, very large keys/values, duplicate overwrites, and deletions.
  • Validate input and handle malformed or truncated streams gracefully with clear error signaling.
  • Time/space complexity should be O(n) in the total serialized data size; support streaming-friendly encoding.
  • Provide unit tests and explain complexity, trade-offs (e.g., delimiter-escaped text vs. length-prefixed binary), and failure recovery.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More OpenAI•More Software Engineer•OpenAI Software Engineer•OpenAI Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.