← 返回 instacart 的题目列表OA: Task Management System
类型:qbank
A CodeSignal OA variant similar in spirit to the database prompt. Implement timestamped CRUD for tasks, priority updates and sorted retrieval, user assignment, scheduled deletion, and historical user task counts.
Requirements
Every method includes a timestamp.
Level 1:
CRUD over tasks.
Each task has task_id and description.
Create, read, update, and delete should respect timestamp order.
Level 2:
updateTaskPriority(timestamp, task_id, priority) changes a task's priority.
getSortedPrioritizedTasks(timestamp) returns tasks sorted by priority. Newly created tasks default to priority 0.
Tie-breakers are likely task id or creation order; read visible tests before locking the comparator.
Level 3:
addUser(timestamp, user_id).
assignTaskToUser(timestamp, task_id, user_id).
unassignTaskToUser(timestamp, task_id, user_id).
scheduleDeletion(timestamp, task_id, delay) schedules the task to be deleted at timestamp + delay.
Scheduled deletion must occur before any other operation at the same timestamp.
Level 4:
getUserTaskNumsAt(timestamp, user_id, time_at) returns the number of tasks assigned to a user at a historical point.
Notes
Maintain current task state plus an event log. Level 4 is much easier if assignments and deletions are appended as events rather than only mutating current maps.
For scheduled deletion, use a min-heap keyed by deletion timestamp. At the start of every public method, process all due deletions with deleteTime <= timestamp before handling the requested operation.
Task state should include description, priority, assignee, deleted, and createdAt.
For historical counts, either replay events up to time_at or maintain per-user timeline deltas: +1 when a task becomes assigned, -1 when unassigned or deleted. Prefix-sum timelines make queries efficient.
Common bug: scheduling deletion for an already-deleted task, then later recreating the same task_id and accidentally applying the old deletion to the new task. Use a generation/version id per task if recreation is allowed.
The test file may be locked, so build your own tiny debug harness inside the solution if the platform permits it.
Preparation
Implement a generic processDueDeletes(timestamp) helper and call it first in every method.
Practice writing a comparator for (-priority, task_id) and adjust after reading expected output.
Test same-timestamp ordering explicitly: scheduled delete at t=10, then assign/update at t=10; delete should win first.