Easy code and beats 100% time and 100% space
Approachuse map and binary heapComplexity
Time complexity:
O(log(n))
Space complexity:
O(n)
Code
# Approach
use map and binary heap
# Complexity
- Time complexity:
O(log(n))
- Space complexity:
O(n)
# Code
```cpp []
class TaskManager {
public:
    priority_queue<tuple<int, int, int> > pq;
    map<int, pair<int, int> > mp;

    TaskManager(vector<vector<int> > &tasks) {
        for (auto v: tasks) {
            int userId = v[0], taskId = v[1], priority = v[2];
            add(userId, taskId, priority);
        }
    }

    void add(int userId, int taskId, int priority) {
        mp[taskId] = {priority, userId};
        pq.push({priority, taskId, userId});
    }

    void edit(int taskId, int newPriority) {
        int userId = mp[taskId].second;
        mp[taskId] = {newPriority, userId};
        pq.push({newPriority, taskId, userId});
    }

    void rmv(int taskId) {
        mp[taskId] = {-1, -1};
    }

    int execTop() {
        while (pq.size()) {
            auto [priority,taskId,userId] = pq.top();
            pq.pop();
            if (mp[taskId].first == priority) {
                rmv(taskId);
                return userId;
            }
        }
        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();
 */
```



['C++']