Python Heap + Map
IntuitionUse a heap + a map to keep track of currently valid tasks.Code
# Intuition
Use a heap + a map to keep track of currently valid tasks.

# Code
```python3 []
class TaskManager:

    def __init__(self, tasks: List[List[int]]):
        self.heap = []
        self.map = {}
        for userId, taskId, priority in tasks:
            self.add(userId, taskId, priority)

    def add(self, userId: int, taskId: int, priority: int) -> None:
        heapTask = [-priority, -taskId, userId]
        heapq.heappush(self.heap, heapTask)
        self.map[taskId] = heapTask

    def edit(self, taskId: int, newPriority: int) -> None:
        self.add(self.map[taskId][2], taskId, newPriority)

    def rmv(self, taskId: int) -> None:
        del self.map[taskId]

    def execTop(self) -> int:
        while self.heap:
            task = heapq.heappop(self.heap)
            taskId = -task[1]
            if taskId in self.map and self.isSameTask(task, self.map[taskId]):
                self.rmv(taskId)
                return task[2]
        return -1
    
    def isSameTask(self, t1, t2) -> bool:
        return t1[0] == t2[0] and t1[1] == t2[1] and t1[2] == t2[2]


```
['Hash Table', 'Design', 'Ordered Map', 'Heap (Priority Queue)', 'Ordered Set', 'Python3']