← 返回 meta 的题目列表In-Memory Database with Record CRUD and Lock/Unlock
类型:online_judge
Problem: Implement an In-Memory Database with Record CRUD and Lock/Unlock
Implement a simplified in-memory database where data is stored by record. Each record is identified by a recordKey and contains multiple fields. You must process a sequence of operations and print the output for each operation.
The system must support:
Basic CRUD: create/update/delete/query records/fields.
Locking: lock and unlock a record; when a record is locked, certain write operations should be denied or return failure (as dictated by the test cases).
Note: The interview note mentions the statement may contain inconsistencies; rely on CodeSignal test cases as the source of truth.
Input Format
Multiple lines, one operation per line.
Each line contains space-separated tokens.
The first token is the operation name; the remaining tokens are arguments.
(The exact set of operations, their parameters, and expected return formats should be inferred from the OA test cases.)
Output Format
Print one line per operation.
Each output can be a boolean/string/number/empty value depending on the operation (per test cases).
Constraints
Aim for near O(#operations) time.
Use 1-2 hash maps/dictionaries as the core data structures.
Example
(Not reliably provided in the interview note; follow the OA examples and tests.)
Core Requirements
Record creation and deletion.
Field insert/overwrite and field deletion.
Record-level lock/unlock.
Behavior of writes while locked (fail/ignore/special return value).
Sample Tests (placeholder only; NOT the original)
input:
SET user1 age 10
LOCK user1
SET user1 age 11
GET user1 age
UNLOCK user1
SET user1 age 11
GET user1 age
output:
true
true
false
10
true
true
11
input:
DELETE user1 age
output:
true
input:
LOCK user2
output:
false
input:
UNLOCK user2
output:
false
input:
GET user_not_exist age
output:
Example
Input
SET user1 age 10
LOCK user1
SET user1 age 11
GET user1 age
UNLOCK user1
SET user1 age 11
GET user1 age
Output
true
true
false
10
true
true
11