Process Operations for an In-Memory Key-Value Store
Company: Rbcroyalbank
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
# Process Operations for an In-Memory Key-Value Store
Implement an in-memory key-value store that supports adding or replacing a value, deleting a key, and querying a key.
```python
def process_operations(operations: list[list[str]]) -> list[str]:
...
```
Each operation has one of these forms:
- `["SET", key, value]`: store `value` under `key`, replacing the previous value if the key already exists.
- `["DELETE", key]`: remove `key` if it exists. Deleting a missing key is a no-op.
- `["GET", key]`: append the current value to the result, or append `"NULL"` if the key is absent.
Return the results of the `GET` operations in encounter order. Keys and values are case-sensitive strings. The literal value `"NULL"` will not appear in a `SET` operation.
## Constraints
- `0 <= len(operations) <= 200_000`
- `1 <= len(key), len(value) <= 100`
- Every operation has the exact arity shown above.
- Aim for expected constant time per operation and linear time overall.
## Examples
```text
Input:
operations = [
["SET", "model", "v1"],
["GET", "model"],
["SET", "model", "v2"],
["GET", "model"],
["DELETE", "model"],
["GET", "model"]
]
Output: ["v1", "v2", "NULL"]
```
```text
Input:
operations = [["DELETE", "missing"], ["GET", "missing"]]
Output: ["NULL"]
```
Quick Answer: Implement a simple in-memory key-value store from a stream of SET, GET, and DELETE operations. This coding exercise checks hash-map updates, replacement and missing-key semantics, ordered query output, and expected constant-time processing at scale.