Task Management System
Updated
Problem statement
Build a task-management service. You get a list of operations, each with a timestamp, and you process them in order.
Every operation starts with its name. Timestamps are strictly increasing.
["ADD_USER", t, userId, quota]creates a user who may have at mostquotaactive 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 if the task is missing or deleted.["UPDATE", t, taskId, priority, dueAt, expiresAt]sets newpriority,dueAt, andexpiresAtvalues for an active task.["DELETE", t, taskId]marks an existing task as deleted, if it is not deleted already.["SEARCH", t, userId]returns the identifiers of that user's active tasks. Sort them by priority from highest to lowest, then by creation time from earliest to latest, then by identifier.["SET_QUOTA", t, userId, quota]changes a user's quota. Lowering it does not remove existing tasks. But the user cannot create new tasks until their number of active tasks is below the quota.["COMPLETE", t, taskId]marks an active task as completed.["HISTORY", t, userId, view]returns task identifiers in the order they were created, earliest first.viewisCOMPLETED,EXPIRED,UNFINISHED, orOVERDUE. Unfinished tasks are the active ones. Overdue tasks are active tasks withdueAt < t.
Before each operation at time t, every active task with expiresAt <= t becomes expired. Completing, deleting, or expiring a task frees one slot in its user's quota.
Return one row for each input operation. Operations that change state return ["OK"] when they succeed. A failure returns one of ["UNKNOWN_USER"], ["DUPLICATE_TASK"], ["QUOTA_EXCEEDED"], ["NOT_FOUND"], or ["NOT_ACTIVE"]. Search and history operations may return an empty row.
Function
processTaskOperations(operations: String[][]) → String[][]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 search lists t2 first because its priority is higher. Completing t2 frees a quota slot. Then the quota is lowered while t1 is still active and uses the only slot, so the next creation fails with QUOTA_EXCEEDED. At the final read, t1 has reached its expiry time, so it becomes expired first and the row shows EXPIRED.
Constraints
1 <= operations.length <= 200000.- All timestamps and task time fields are integers in
[0, 10^9]; operation timestamps are strictly increasing. - For every
CREATEorUPDATE,operation timestamp < dueAt < expiresAt. - User and task identifiers are nonempty ASCII strings of at most
40characters. - Priority is an integer in
[-10^9, 10^9]; quota is in[0, 200000]. ADD_USERuses a new user identifier.SET_QUOTA,SEARCH, andHISTORYname an existing user.- The total number of task records examined by all
SEARCHandHISTORYoperations is at most200000.
More Anthropic interview questions
- Repair the Bootloader ProgramOA · ONSITE INTERVIEW · Seen Sep 2026
- Normalize a DNS Domain NameOA · Seen May 2026
- Worker Management, Part 4: Double-Paid IntervalsOA · Seen May 2026
- In-Memory Database with Backup and RestoreOA · Seen May 2026
- In-Memory Database Historical LookupOA · Seen Nov 2025
- Banking Pending Transfer AcceptanceOA · Seen Jul 2024
- Fair Coin from a Biased CoinPHONE SCREEN · Seen Nov 2026
- Crawl Same-Hostname URLs ConcurrentlyPHONE SCREEN · Seen Oct 2026
- Longest-Match Tokenizer with Unknown SymbolsONSITE INTERVIEW · Seen Oct 2026
- Recover a Function-Call LRU Cache with a Write-Ahead LogONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- In-Memory File SystemAirbnb · OAAirbnb interview questions
- Power Cell BankOptiver · OAOptiver interview questions
- Four-Level Banking System with Scheduled PaymentsZipRecruiter · OAZipRecruiter interview questions
- Task Management SystemCoinbase · OACoinbase interview questions
- Progressive Parcel Tracking OperationsKlaviyo · OAKlaviyo interview questions
- Versioned Recipe SystemThe Trade Desk · OA
- Recipe Management SystemRamp · OARamp interview questions
- Document and Layer OperationsFigma · OAFigma interview questions
- Worker Management with Promotions and Double-Paid TimeInstacart · ONSITE INTERVIEWInstacart interview questions
- Document Enrichment Stream AggregatorBloomberg LP · PHONE SCREENBloomberg LP interview questions