Design Task Manager
Learn this problemProblem statement
Manage tasks owned by users. Every task has a unique integer taskId, an integer userId, and an integer priority. The initial array tasks contains rows [userId, taskId, priority].
For this exercise, process the finite batch operations. Each row is one of:
["ADD", userId, taskId, priority]: add a task. The suppliedtaskIdis not currently present.["EDIT", taskId, newPriority]: change the priority of an existing task.["RMV", taskId]: remove an existing task.["EXEC_TOP"]: execute and remove the task with the greatest priority. If several tasks have that priority, execute the one with the greatesttaskId. Return itsuserId, or-1when no task is available.
The numeric fields in operations are decimal strings. Return the result of every EXEC_TOP operation in order.
Function
runTaskManager(tasks: int[][], operations: String[][]) → int[]Examples
Example 1
tasks = [[1,101,10],[2,102,20],[3,103,15]]operations = [["ADD","4","104","5"],["EDIT","102","8"],["EXEC_TOP"],["RMV","101"],["ADD","5","105","15"],["EXEC_TOP"]]return = [3,5]After task 102 is lowered to priority 8, task 103 is the first task executed, so the first result is user 3. Task 101 is removed, and newly added task 105 is then the highest-priority task, so the second result is user 5.
Example 2
tasks = [[1,10,5],[2,20,5]]operations = [["EXEC_TOP"],["EDIT","10","7"],["EXEC_TOP"],["EXEC_TOP"]]return = [2,1,-1]The initial priority tie is broken by the larger task ID, so task 20 returns user 2. Editing task 10 makes it the next result. The final execution finds no task and returns -1.
Constraints
1 <= tasks.length <= 10^5- Every initial row is
[userId, taskId, priority], and initial task IDs are unique. 0 <= userId, taskId <= 10^50 <= priority, newPriority <= 10^90 <= operations.length <= 2 * 10^5- Every operation has a valid name and arity.
- An
ADDtask ID is absent when added; anEDITorRMVtask ID is present when used.
More Apple problems
- Insert IntervalPHONE SCREEN · Seen Jul 2026
- Group Transitive String AliasesPHONE SCREEN · Seen Jul 2026
- Unit Conversion IIPHONE SCREEN · Seen Jul 2026
- Two-Color an Undirected GraphPHONE SCREEN · Seen Jul 2026
- Word Search IIPHONE SCREEN · Seen Jul 2026
- Phone DirectoryPHONE SCREEN · Seen Jul 2026
- Product Except Self With ZerosONSITE INTERVIEW · Seen Jul 2026
- Subset Sum PossibleONSITE INTERVIEW · Seen Jul 2026