Katkat

Implement in-memory database insert and delete operations

OpenAIMachine Learning Engineer · Onsite

Last updated

This question evaluates understanding of data structures and algorithmic complexity in the context of designing a key-value in-memory database, and it falls under the Coding & Algorithms domain for a Machine Learning Engineer role while focusing on practical implementation skills.

Design and implement a simple in-memory database (key-value store) that supports the following operations:

  • insert(key, value): Insert a key-value pair into the database. If the key already exists, update its value.
  • get(key): Return the value associated with the key, or indicate that the key does not exist.
  • delete(key): Remove the key and its associated value from the database if it exists.

Assume:

  • Keys are strings.
  • Values are arbitrary strings (or integers; choose one and be consistent).
  • The database is entirely in memory; you do not need to persist data to disk.
  • You do not need to handle concurrency/multi-threading.

Requirements:

  • Design the data structures used to support these operations.
  • Aim for average O(1) time for insert, get, and delete.
  • Explain the time and space complexity of your approach.

Then, write code to implement these operations in the programming language of your choice.