Task Management System
Problem statement
Implement a task-management service by processing a finite sequence of timestamped operations in order.
Every operation begins with an opcode. Timestamps are strictly increasing.
["ADD_USER", t, userId, quota]creates a user with a maximum number of active tasks.["CREATE", t, taskId, userId, priority, dueAt, expiresAt]creates an active task. It fails if the task identifier already exists, the user does not exist, or the user's active-task quota is full.["GET", t, taskId]returns[taskId, userId, priority, createdAt, dueAt, expiresAt, status], or an empty row for a missing or deleted task.["UPDATE", t, taskId, priority, dueAt, expiresAt]updates an active task.["DELETE", t, taskId]marks an existing non-deleted task as deleted.["SEARCH", t, userId]returns that user's active task identifiers ordered by decreasing priority, then increasing creation timestamp, then identifier.["SET_QUOTA", t, userId, quota]changes a user's quota. Lowering it does not remove existing tasks, but new tasks remain blocked until the active count is below the quota.["COMPLETE", t, taskId]marks an active task completed.["HISTORY", t, userId, view]returns identifiers in increasing creation order.viewisCOMPLETED,EXPIRED,UNFINISHED, orOVERDUE. Unfinished tasks are active; overdue tasks are active tasks withdueAt < t.
Before each operation at time t, every active task with expiresAt <= t becomes expired. Completion, deletion, and expiration free an active-task quota slot.
Examples
Example 1
operations = [["ADD_USER","1","u1","2"],["CREATE","2","t1","u1","5","10","20"],["CREATE","3","t2","u1","7","4","30"],["SEARCH","5","u1"],["COMPLETE","6","t2"],["HISTORY","7","u1","COMPLETED"],["SET_QUOTA","8","u1","1"],["CREATE","9","t3","u1","9","12","40"],["GET","20","t1"]]return = [["OK"],["OK"],["OK"],["t2","t1"],["OK"],["t2"],["OK"],["QUOTA_EXCEEDED"],["t1","u1","5","2","10","20","EXPIRED"]]The higher-priority task is returned first. Completing it frees a quota slot, but the later quota reduction leaves one active task, so the next creation is rejected. The final read first expires t1.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- Worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
Pro subscription, billed yearly — or $19 month-to-month. Cancel anytime.