Task Manager with Timed Assignments
Problem statement
Process a finite sequence of operations for an initially empty task manager. Return one row of strings for every operation, in input order. The four levels below are cumulative.
Every operation is a row of strings. Its first entry is the operation name and its second entry is a positive integer timestamp written as a decimal string. Operation timestamps strictly increase. All IDs and task-name comparisons are case-sensitive.
Level 1: Task records
["ADD_TASK", timestamp, name, priority]: create a task with the given name and nonnegative priority. Return its ID in one cell. IDs aretask_id_1,task_id_2, and so on. Tasks with equal names and priorities are allowed.["UPDATE_TASK", timestamp, taskId, name, priority]: replace an existing task's name and priority. Return["true"]on success or["false"]when the task does not exist. Updating a task does not change its creation order.["GET_TASK", timestamp, taskId]: return one compact JSON string with the keysnameand thenpriority, for example["{\"name\":\"Write tests\",\"priority\":5}"]. Preserve all spaces within the name. For this exercise, encode a quotation mark as\"and a backslash as\\inside the name; write every other permitted character literally. For this exercise, represent a missing task by an empty row[].
Level 2: Search and ordering
["SEARCH_TASKS", timestamp, nameFilter, maxResults]: select current task names containing the exact case-sensitive substringnameFilter. An empty filter matches every task.["LIST_TASKS_SORTED", timestamp, limit]: select all tasks.- Both operations return task IDs sorted by priority descending, then original numeric creation order ascending. Truncate to the requested limit. A nonpositive limit returns
[].
Level 3: Users and timed assignments
["ADD_USER", timestamp, userId, quota]: for this exercise, create a user and return["true"]only if the ID is new. A duplicate ID returns["false"]and preserves the original quota. A zero quota is allowed.["ASSIGN_TASK", timestamp, taskId, userId, finishTime]: create a separate assignment record for the existing task and user. An assignment is active when it is uncompleted and its interval[assignmentTime, finishTime)contains the current timestamp.- Return
["false"]if the task or user is missing, if the user's active-assignment quota is full, or, for this exercise, iffinishTime <= timestamp. Otherwise, return["true"]. - The same task may have multiple concurrent assignments, including repeated assignments to the same user. Each active assignment consumes one quota slot independently.
["GET_USER_TASKS", timestamp, userId]: return one task ID per currently active assignment to that user, sorted by finish time ascending and then assignment timestamp ascending. Keep duplicate task IDs. For this exercise, a missing user returns[].
Level 4: Completion and overdue assignments
["COMPLETE_TASK", timestamp, taskId, userId]: among the matching user's active, uncompleted assignments of this task, complete the one with the earliest assignment timestamp. Return["true"]and immediately release its quota slot. Return["false"]if no such record exists.- An assignment cannot be completed at or after its finish time because its active interval excludes that endpoint.
["GET_OVERDUE_ASSIGNMENTS", timestamp, userId]: return one task ID per uncompleted assignment to that user withfinishTime <= timestamp. Sort by finish time ascending and then assignment timestamp ascending. Keep duplicate IDs from separate records. For this exercise, a missing user returns[].- A completed assignment never appears in future active or overdue lists. Queries do not consume or remove records. Changing task metadata does not change existing assignment identity or timestamps.
Output rows
Task creation returns one ID, Boolean operations return one lowercase Boolean string, and an existing-task lookup returns one JSON string. List operations return zero or more task IDs directly as the row's cells. A failed mutation leaves tasks, users, counters, and assignment records unchanged.
Function
manageTasks(operations: String[][]) → String[][]Examples
Example 1
operations = [["ADD_TASK","1","Alpha","2"],["ADD_TASK","2","Beta","5"],["ADD_TASK","3","Alpha note","5"],["GET_TASK","4","task_id_1"],["SEARCH_TASKS","5","Alpha","10"],["LIST_TASKS_SORTED","6","2"],["UPDATE_TASK","7","task_id_1"," Alpha \"Q\" ","5"],["GET_TASK","8","task_id_1"],["LIST_TASKS_SORTED","9","3"]]return = [["task_id_1"],["task_id_2"],["task_id_3"],["{\"name\":\"Alpha\",\"priority\":2}"],["task_id_3","task_id_1"],["task_id_2","task_id_3"],["true"],["{\"name\":\" Alpha \\\"Q\\\" \",\"priority\":5}"],["task_id_1","task_id_2","task_id_3"]]The search returns only names containing Alpha, with higher priority first. Listing breaks equal-priority ties by numeric creation order. Updating task 1 changes its metadata but preserves its original creation order. The returned JSON preserves the name's leading and trailing spaces and escapes its quotation marks.
Example 2
operations = [["ADD_TASK","1","A","1"],["ADD_TASK","2","B","2"],["ADD_USER","3","u","3"],["ASSIGN_TASK","4","task_id_1","u","20"],["ASSIGN_TASK","5","task_id_1","u","10"],["ASSIGN_TASK","6","task_id_2","u","15"],["GET_USER_TASKS","7","u"],["COMPLETE_TASK","8","task_id_1","u"],["GET_USER_TASKS","9","u"],["GET_OVERDUE_ASSIGNMENTS","10","u"],["ASSIGN_TASK","11","task_id_1","u","25"],["GET_USER_TASKS","12","u"]]return = [["task_id_1"],["task_id_2"],["true"],["true"],["true"],["true"],["task_id_1","task_id_2","task_id_1"],["true"],["task_id_1","task_id_2"],["task_id_1"],["true"],["task_id_2","task_id_1"]]The two assignments of task 1 are separate records and each uses one quota slot. At time 7, the list is ordered by finish times 10, 15, and 20. Completion at time 8 removes the earliest assigned matching record, created at time 4 with finish time 20. The later assignment ending at 10 remains and becomes overdue exactly at time 10.
Example 3
operations = [["ADD_TASK","1","X","0"],["ADD_USER","2","u","1"],["ASSIGN_TASK","3","task_id_1","u","5"],["ASSIGN_TASK","4","task_id_1","u","9"],["GET_USER_TASKS","5","u"],["GET_OVERDUE_ASSIGNMENTS","6","u"],["COMPLETE_TASK","7","task_id_1","u"],["ASSIGN_TASK","8","task_id_1","u","11"],["COMPLETE_TASK","9","task_id_1","u"],["GET_OVERDUE_ASSIGNMENTS","10","u"],["GET_USER_TASKS","11","u"]]return = [["task_id_1"],["true"],["true"],["false"],[],["task_id_1"],["false"],["true"],["true"],["task_id_1"],[]]The first assignment fills the quota until time 5. At that exact finish time it is no longer active. It remains overdue because it was never completed, and an expired assignment cannot be completed. The later assignment completes at time 9, so it is absent from both future active and overdue lists.
Constraints
- For this exercise, assume
1 <= operations.length <= 200. Every operation has a recognized name and the correct number of fields. - Operation timestamps strictly increase, and both timestamps and finish times are positive integers. For this exercise, assume each is at most
10^9. - For this exercise, assume priorities are integers in
[0, 10^9], quotas in[0, 1000], and result limits in[-10^9, 10^9]. - For this exercise, assume task names contain
1to80printable ASCII characters, including spaces, quotation marks, and backslashes. Filters contain0to80printable ASCII characters. Printable ASCII means code points32through126; control characters are excluded. - For this exercise, assume input user IDs and task IDs contain
1to40ASCII letters, digits, underscores, or hyphens. - Numeric arguments use canonical decimal strings: digits, with a leading minus only for negative limits.