← 返回 coinbase 的题目列表In-Memory DB with per-key user lock: setByUser/deleteByUser/lock/unlock
类型:online_judge
Problem: In-Memory DB Variant — Add User-based locking
You are implementing a simplified in-memory database storing key -> record. This variant introduces users and a lock mechanism per key/record.
Locking rules
A key can be locked by a user.
The user holding the lock can modify the data for that key.
Any non-lock-holding user must not be allowed to modify that key (the operation should fail / be rejected as specified).
Functions to implement (at least)
Implement the following operations (exact signatures/return values are defined by the OA):
setByUser(user, key, ...)
deleteByUser(user, key, ...)
lock(user, key)
unlock(user, key)
Output/Return
Return the required status for lock/unlock and for modification attempts without proper lock ownership.
Constraints / edge cases (per OA)
Behavior when key does not exist.
Re-locking by the same user.
Unlock attempts by non-owner.
Whether there is a wait queue, re-entrant locks, expiry, etc.
Note: The original post only captures the core idea; the full I/O format and edge conditions are not included. Follow the OA statement.
Example
Input
N/A (depends on OA command format)
Output
N/A