Title: #3408 - Design Task Manager - LeetCode JavaScript Solutions
Open Graph Title: #3408 - Design Task Manager - LeetCode JavaScript Solutions
X Title: #3408 - Design Task Manager - LeetCode JavaScript Solutions
Description: There is a task management system that allows users to manage their tasks, each associated with a priority. The system should efficiently ha...
Open Graph Description: There is a task management system that allows users to manage their tasks, each associated with a priority. The system should efficiently ha...
X Description: There is a task management system that allows users to manage their tasks, each associated with a priority. The system should efficiently ha...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/design-task-manager
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/design-task-manager","name":"#3408 - Design Task Manager - LeetCode JavaScript Solutions","description":"There is a task management system that allows users to manage their tasks, each associated with a priority. The system should efficiently ha...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {number[][]} tasks\n */\nvar TaskManager = function(tasks) {\n this.taskRegistry = {};\n this.priorityHeap = new PriorityQueue((a, b) => {\n return a.priority !== b.priority ? b.priority - a.priority : b.taskId - a.taskId;\n });\n\n for (const [userId, taskId, priority] of tasks) {\n this.taskRegistry[taskId] = { userId, priority, version: 1 };\n this.priorityHeap.enqueue({ taskId, priority, version: 1 });\n }\n};\n\n/**\n * @param {number} userId\n * @param {number} taskId\n * @param {number} priority\n * @return {void}\n */\nTaskManager.prototype.add = function(userId, taskId, priority) {\n this.taskRegistry[taskId] = { userId, priority, version: 1 };\n this.priorityHeap.enqueue({ taskId, priority, version: 1 });\n};\n\n/**\n * @param {number} taskId\n * @param {number} newPriority\n * @return {void}\n */\nTaskManager.prototype.edit = function(taskId, newPriority) {\n const currentTask = this.taskRegistry[taskId];\n currentTask.priority = newPriority;\n currentTask.version++;\n this.priorityHeap.enqueue({ taskId, priority: newPriority, version: currentTask.version });\n};\n\n/**\n * @param {number} taskId\n * @return {void}\n */\nTaskManager.prototype.rmv = function(taskId) {\n delete this.taskRegistry[taskId];\n};\n\n\n/**\n * @return {number}\n */\nTaskManager.prototype.execTop = function() {\n while (!this.priorityHeap.isEmpty()) {\n const { taskId, priority, version } = this.priorityHeap.dequeue();\n const activeTask = this.taskRegistry[taskId];\n\n if (activeTask && activeTask.priority === priority && activeTask.version === version) {\n const executedUserId = activeTask.userId;\n delete this.taskRegistry[taskId];\n return executedUserId;\n }\n }\n return -1;\n};","keywords":"LeetCode 3408, #3408 - Design Task Manager, Medium, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/design-task-manager |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/design-task-manager/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/3408-design-task-manager.js |
| Hash Table | https://leetcodejavascript.com/tags/hash-table |
| Heap Priority Queue | https://leetcodejavascript.com/tags/heap-priority-queue |
| Design | https://leetcodejavascript.com/tags/design |
| Ordered Set | https://leetcodejavascript.com/tags/ordered-set |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width,initial-scale=1
Robots: index, follow