Quick Overview

This question evaluates understanding of core data structures, API design, complexity analysis, and edge-case handling for an in-memory key–value CRUD store, and falls under the Coding & Algorithms domain while testing both practical implementation skills and conceptual reasoning about time/space trade-offs.

Implement a key-value CRUD store

Company: DocuSign

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Implement an in-memory key–value store that supports create, read, update, and delete operations. Expose APIs such as put(key, value), get(key), update(key, value), delete(key), and exists(key). Choose and justify an underlying data structure (e.g., a B-tree or another ordered index) and analyze time and space complexity. Discuss edge cases like overwriting existing keys and missing keys.

Overview: This question evaluates understanding of core data structures, API design, complexity analysis, and edge-case handling for an in-memory key–value CRUD store, and falls under the Coding & Algorithms domain while testing both practical implementation skills and conceptual reasoning about time/space trade-offs.

Implement the behavior of an in-memory key-value store. Since the judge calls a single function rather than individual methods, each API call is represented as an operation in a list. The store must support put(key, value), get(key), update(key, value), delete(key), and exists(key). Use exact-key lookup semantics: a hash map/dictionary is the appropriate underlying data structure because the APIs do not require sorted traversal or range queries. If sorted operations were required, an ordered index such as a B-tree could be justified, but for these operations a hash map provides better expected lookup performance.

Constraints

  • 0 <= len(operations) <= 100000
  • Each operation is valid and uses one of: 'put', 'get', 'update', 'delete', 'exists'
  • Keys and values are non-empty strings with length at most 100
  • Values will not be any reserved output token: 'CREATED', 'OVERWRITTEN', 'UPDATED', 'DELETED', 'NOT_FOUND', 'true', or 'false'

Examples

Input: ([['put','user:1','Alice'], ['get','user:1'], ['exists','user:1'], ['update','user:1','Alicia'], ['get','user:1'], ['delete','user:1'], ['get','user:1'], ['exists','user:1']],)

Expected Output: ['CREATED', 'Alice', 'true', 'UPDATED', 'Alicia', 'DELETED', 'NOT_FOUND', 'false']

Explanation: The key is created, read, updated, deleted, and then no longer exists.

Input: ([['put','a','1'], ['put','a','2'], ['get','a'], ['update','b','3'], ['delete','b'], ['exists','a']],)

Expected Output: ['CREATED', 'OVERWRITTEN', '2', 'NOT_FOUND', 'NOT_FOUND', 'true']

Explanation: The second put overwrites key 'a'. Updating and deleting missing key 'b' both fail.

Hints

  1. Only exact-key operations are required, so think about a structure that can check whether a key exists in expected O(1) time.
  2. Be careful to distinguish put from update: put can overwrite an existing key, while update should fail when the key is missing.

Implement a Key-Value CRUD Store

mediumDocuSignSoftware Engineer

Implement the behavior of an in-memory key-value store. Since the judge calls a single function rather than individual methods, each API call is represented as an operation in a list. The store must support put(key, value), get(key), update(key, value), delete(key), and exists(key). Use exact-key lookup semantics: a hash map/dictionary is the appropriate underlying data structure because the APIs do not require sorted traversal or range queries. If sorted operations were required, an ordered index such as a B-tree could be justified, but for these operations a hash map provides better expected lookup performance.

Examples

Example 1
Input
([['put','user:1','Alice'], ['get','user:1'], ['exists','user:1'], ['update','user:1','Alicia'], ['get','user:1'], ['delete','user:1'], ['get','user:1'], ['exists','user:1']],)
Output
['CREATED', 'Alice', 'true', 'UPDATED', 'Alicia', 'DELETED', 'NOT_FOUND', 'false']
Notes
The key is created, read, updated, deleted, and then no longer exists.
Example 2
Input
([['put','a','1'], ['put','a','2'], ['get','a'], ['update','b','3'], ['delete','b'], ['exists','a']],)
Output
['CREATED', 'OVERWRITTEN', '2', 'NOT_FOUND', 'NOT_FOUND', 'true']
Notes
The second put overwrites key 'a'. Updating and deleting missing key 'b' both fail.

Constraints

  • •0 <= len(operations) <= 100000
  • •Each operation is valid and uses one of: 'put', 'get', 'update', 'delete', 'exists'
  • •Keys and values are non-empty strings with length at most 100
  • •Values will not be any reserved output token: 'CREATED', 'OVERWRITTEN', 'UPDATED', 'DELETED', 'NOT_FOUND', 'true', or 'false'

Comments (0)

No comments yet. Be the first to comment!

Submit your answer

Approved first answer today earns 30 XP
Bold⌘BItalic⌘IInline code⌘`Bullet listTab to nest (○ ■)Numbered listTab to nest (a. i.)QuoteCode block
Formatting help
Signature
def solution(operations: list[list[str]]) -> list[str]:
Sample call
solution([['put','user:1','Alice'], ['get','user:1'], ['exists','user:1'], ['update','user:1','Alicia'], ['get','user:1'], ['delete','user:1'], ['get','user:1'], ['exists','user:1']])
Language
Case 1
Input
([['put','user:1','Alice'], ['get','user:1'], ['exists','user:1'], ['update','user:1','Alicia'], ['get','user:1'], ['delete','user:1'], ['get','user:1'], ['exists','user:1']],)
Expected
['CREATED', 'Alice', 'true', 'UPDATED', 'Alicia', 'DELETED', 'NOT_FOUND', 'false']
Case 2
Input
([['put','a','1'], ['put','a','2'], ['get','a'], ['update','b','3'], ['delete','b'], ['exists','a']],)
Expected
['CREATED', 'OVERWRITTEN', '2', 'NOT_FOUND', 'NOT_FOUND', 'true']

Browse More Questions