Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Key-Value Store Implementation

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Key-Value Store Implementation. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Implement an in-memory key/value store that could support lightweight state for a Substack publishing workflow. Build the store without using Python's built-in dictionary for storing entries.

Your implementation must use a fixed-size bucket array and separate chaining to resolve hash collisions.

Formal Specification

Create a KeyValueStore class with these methods:

  1. put(key, value): Insert or replace the integer value associated with a non-empty string key.
  2. get(key): Return the associated value, or None if the key does not exist.
  3. delete(key): Remove the key and return True if it existed, otherwise return False.
  4. contains(key): Return whether the key exists.

For automated testing, implement run_operations(operations, capacity) that creates a store and executes operations. Each operation is an array such as ["put", "draft-1", 42], ["get", "draft-1"], ["delete", "draft-1"], or ["contains", "draft-1"]. Return results only for get, delete, and contains, in execution order.

Constraints

  • 1 <= len(operations) <= 10^4
  • 1 <= capacity <= 10^3
  • Keys are non-empty strings of at most 100 characters
  • Values are integers in the range [-10^9, 10^9]
  • Every operation is valid and uses put, get, delete, or contains

Function Signature

def run_operations(operations, capacity):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output