-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3408_Design_Task_Manager.txt
More file actions
39 lines (38 loc) · 1.19 KB
/
3408_Design_Task_Manager.txt
File metadata and controls
39 lines (38 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class TaskManager {
priority_queue<pair<int, int>> tasks;
unordered_map<int, int> taskPriority;
unordered_map<int, int> taskOwner;
public:
TaskManager(vector<vector<int>>& tasks) {
for(const auto& task : tasks) { add(task[0], task[1], task[2]); }
}
void add(int userId, int taskId, int priority) {
tasks.push({priority, taskId});
taskPriority[taskId] = priority;
taskOwner[taskId] = userId;
}
void edit(int taskId, int newPriority) {
tasks.push({newPriority, taskId});
taskPriority[taskId] = newPriority;
}
void rmv(int taskId) { taskPriority[taskId] = -1; }
int execTop() {
while(!tasks.empty()) {
const auto task = tasks.top();
tasks.pop();
if(task.first == taskPriority[task.second]) {
taskPriority[task.second] = -1;
return taskOwner[task.second];
}
}
return -1;
}
};
/**
* Your TaskManager object will be instantiated and called as such:
* TaskManager* obj = new TaskManager(tasks);
* obj->add(userId,taskId,priority);
* obj->edit(taskId,newPriority);
* obj->rmv(taskId);
* int param_4 = obj->execTop();
*/