Python3 | Explained | Simple Solution
Intuitionuse (priority, task, userid) in a heap
use taskid -> (priority, userid) taskMap to store if a task with taskidto add a task. simply push to heap and up
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
use (priority, task, userid) in a heap
use taskid -> (priority, userid) taskMap to store if a task with taskid 

to add a task. simply push to heap and update the taskMap
to remove a task. ***ignore heap updates***. remove the task entry from taskMap
to edit -> is same as remove and add

to fetch top task to execute
we might have a task with priority 100 and then later updated to 10; as mentioned above we will have two entries in our heap because of ***ignore heap updates*** above. So when fetching the top heap item we need to verify if such task exist with such high priority from the taskMap. if not just ignore that task


# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
add -> logN
edit -> logN
execTop -> MlogM (we might be removing all items from the list worse case, where M is N + edit count)
rmv -> 1

- Space complexity:
M

# Code
```python3 []
import heapq
class TaskManager:

    def __init__(self, tasks: List[List[int]]):
        self.pheap = []
        self.tmap = {}
        
        for task in tasks:
            uid, tid, p = tuple(task)
            self.add(uid, tid, p)
        

    def add(self, userId: int, taskId: int, priority: int) -> None:

        heapq.heappush(self.pheap, (-priority, -taskId, userId))
        self.tmap[taskId] = (priority, userId)
        

    def edit(self, taskId: int, newPriority: int) -> None:
        oldPriority, uid = self.tmap[taskId]
        self.tmap[taskId] = None
        self.add(uid, taskId, newPriority)
        

    def rmv(self, taskId: int) -> None:
        self.tmap[taskId] = None
        

    def execTop(self) -> int:

        #print(self.pheap)

        if not self.pheap: 
            return -1


        p, t, u = heapq.heappop(self.pheap)
        if self.tmap[-t] and self.tmap[-t][0] == -p:
            self.tmap[-t] = None
            return u


        return self.execTop()

        


            
        


# Your TaskManager object will be instantiated and called as such:
# obj = TaskManager(tasks)
# obj.add(userId,taskId,priority)
# obj.edit(taskId,newPriority)
# obj.rmv(taskId)
# param_4 = obj.execTop()
```
['Python3']