Using map and maxHeap 
IntuitionApproach
Take a priority queue and push all task in to it
Take an unordered_map and keep track of valid and invalid taskids
When we edit a task we upda
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
- Take a priority queue and push all task in to it
- Take an unordered_map and keep track of valid and invalid taskids
- When we edit a task we update the map as well to latest priority 
- When we remove the task we mark the priority to -1 on the map.
- When we fetch the task from priority queue, if the priroity is not matching with the map priority then it imples that the task on the priority queue is stale and no longer valid so just skip it.

Note: In the problem its written that during exec of tie with priority need to return the highest taskid but actually we need to return the task with highest user_id and if user id tie then only need to return the highest task id. This is as per the test cases updated.

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
auto comp = [](vector<int>& a, vector<int>& b){
    if(a[2] == b[2]){
        if(a[1] == b[1]) return a[0] < b[0];
        return a[1] < b[1];
    } 
    return a[2] < b[2];
};

class TaskManager {
public:
    unordered_map<int, pair<int,int>> taskIdToPriority;
    priority_queue<vector<int>, vector<vector<int>>, decltype(comp)> pq;
    TaskManager(vector<vector<int>>& tasks) {
        for(auto t: tasks) {
            pq.push(t);
            taskIdToPriority[t[1]] = {t[0], t[2]};
        }
    }
    
    void add(int userId, int taskId, int priority) {
        vector<int> t= {userId, taskId, priority};
        pq.push(t);
        taskIdToPriority[t[1]] = {t[0], t[2]};
    }
    
    void edit(int taskId, int newPriority) {
        int userId = taskIdToPriority[taskId].first;
        vector<int> t= {userId, taskId, newPriority};
        pq.push(t);
        taskIdToPriority[t[1]] = {t[0], t[2]};
    }
    
    void rmv(int taskId) {
        taskIdToPriority[taskId].second = -1;
    }
    
    int execTop() {
        while(!pq.empty() && taskIdToPriority[pq.top()[1]].second != pq.top()[2]) pq.pop();
        if(pq.empty()) return -1;
        vector<int> t = pq.top(); 
        taskIdToPriority[t[1]].second = -1;
        pq.pop();
        return t[0];
    }
};
```


---

<b>Here is an article of my last interview experience - A Journey to FAANG Company, I recomand you to go through this to know which all resources I have used & how I cracked interview at Amazon:
https://leetcode.com/discuss/interview-experience/3171859/Journey-to-a-FAANG-Company-Amazon-or-SDE2-(L5)-or-Bangalore-or-Oct-2022-Accepted

---
['C++']