Implement a key-value CRUD store
Company: DocuSign
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Onsite
Quick Answer: 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.
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.
Input: ([['delete','x'], ['put','x','first'], ['delete','x'], ['put','x','second'], ['get','x']],)
Expected Output: ['NOT_FOUND', 'CREATED', 'DELETED', 'CREATED', 'second']
Explanation: Deleting a missing key returns 'NOT_FOUND'. After deletion, the same key can be created again.
Input: ([],)
Expected Output: []
Explanation: With no operations, the result list is empty.
Input: ([['put','k1','v1'], ['put','k2','v2'], ['update','k1','v3'], ['exists','k2'], ['delete','k2'], ['exists','k2'], ['get','k1']],)
Expected Output: ['CREATED', 'CREATED', 'UPDATED', 'true', 'DELETED', 'false', 'v3']
Explanation: Multiple keys are stored independently. Deleting 'k2' does not affect the updated value of 'k1'.
Hints
- Only exact-key operations are required, so think about a structure that can check whether a key exists in expected O(1) time.
- Be careful to distinguish put from update: put can overwrite an existing key, while update should fail when the key is missing.