3408. Design Task Manager Medium

@problem@discussion
#Hash Table#Design#Heap (Priority Queue)#Ordered Set



1/**
2 * [3408] Design Task Manager
3 *
4 * There is a task management system that allows users to manage their tasks, each associated with a priority. The system should efficiently handle adding, modifying, executing, and removing tasks.
5 * Implement the TaskManager class:
6 * 
7 * 	
8 * 	TaskManager(vector<vector<int>>&amp; tasks) initializes the task manager with a list of user-task-priority triples. Each element in the input list is of the form [userId, taskId, priority], which adds a task to the specified user with the given priority.
9 * 	
10 * 	
11 * 	void add(int userId, int taskId, int priority) adds a task with the specified taskId and priority to the user with userId. It is guaranteed that taskId does not exist in the system.
12 * 	
13 * 	
14 * 	void edit(int taskId, int newPriority) updates the priority of the existing taskId to newPriority. It is guaranteed that taskId exists in the system.
15 * 	
16 * 	
17 * 	void rmv(int taskId) removes the task identified by taskId from the system. It is guaranteed that taskId exists in the system.
18 * 	
19 * 	
20 * 	int execTop() executes the task with the highest priority across all users. If there are multiple tasks with the same highest priority, execute the one with the highest taskId. After executing, the taskId is removed from the system. Return the userId associated with the executed task. If no tasks are available, return -1.
21 * 	
22 * 
23 * Note that a user may be assigned multiple tasks.
24 *  
25 * <strong class="example">Example 1:
26 * <div class="example-block">
27 * Input:<br />
28 * <span class="example-io">["TaskManager", "add", "edit", "execTop", "rmv", "add", "execTop"]<br />
29 * [[[[1, 101, 10], [2, 102, 20], [3, 103, 15]]], [4, 104, 5], [102, 8], [], [101], [5, 105, 15], []]</span>
30 * Output:<br />
31 * <span class="example-io">[null, null, null, 3, null, null, 5] </span>
32 * Explanation
33 * TaskManager taskManager = new TaskManager([[1, 101, 10], [2, 102, 20], [3, 103, 15]]); // Initializes with three tasks for Users 1, 2, and 3.<br />
34 * taskManager.add(4, 104, 5); // Adds task 104 with priority 5 for User 4.<br />
35 * taskManager.edit(102, 8); // Updates priority of task 102 to 8.<br />
36 * taskManager.execTop(); // return 3. Executes task 103 for User 3.<br />
37 * taskManager.rmv(101); // Removes task 101 from the system.<br />
38 * taskManager.add(5, 105, 15); // Adds task 105 with priority 15 for User 5.<br />
39 * taskManager.execTop(); // return 5. Executes task 105 for User 5.</div>
40 *  
41 * Constraints:
42 * 
43 * 	1 <= tasks.length <= 10^5
44 * 	0 <= userId <= 10^5
45 * 	0 <= taskId <= 10^5
46 * 	0 <= priority <= 10^9
47 * 	0 <= newPriority <= 10^9
48 * 	At most 2 * 10^5 calls will be made in total to add, edit, rmv, and execTop methods.
49 * 	The input is generated such that taskId will be valid.
50 * 
51 */
52pub struct Solution {}
53
54// problem: https://leetcode.com/problems/design-task-manager/
55// discuss: https://leetcode.com/problems/design-task-manager/discuss/?currentPage=1&orderBy=most_votes&query=
56
57// submission codes start here
58
59struct TaskManager {
60        false
61    }
62
63
64/** 
65 * `&self` means the method takes an immutable reference.
66 * If you need a mutable reference, change it to `&mut self` instead.
67 */
68impl TaskManager {
69
70    fn new(tasks: Vec<Vec<i32>>) -> Self {
71        
72    }
73    
74    fn add(&self, user_id: i32, task_id: i32, priority: i32) {
75        
76    }
77    
78    fn edit(&self, task_id: i32, new_priority: i32) {
79        
80    }
81    
82    fn rmv(&self, task_id: i32) {
83        
84    }
85    
86    fn exec_top(&self) -> i32 {
87        
88    }
89}
90
91/**
92 * Your TaskManager object will be instantiated and called as such:
93 * let obj = TaskManager::new(tasks);
94 * obj.add(userId, taskId, priority);
95 * obj.edit(taskId, newPriority);
96 * obj.rmv(taskId);
97 * let ret_4: i32 = obj.exec_top();
98 */
99
100// submission codes end
101
102#[cfg(test)]
103mod tests {
104    use super::*;
105
106    #[test]
107    fn test_3408() {
108    }
109}
110


Back
© 2025 bowen.ge All Rights Reserved.