[LeetCode] Design Event Manager

3885. Design Event Manager

You are given an initial list of events, where each event has a unique eventId and a priority.

Implement the EventManager class:

  • EventManager(int[][] events) Initializes the manager with the given events, where events[i] = [eventId_i, priority_​​​​​​​i].
  • void updatePriority(int eventId, int newPriority) Updates the priority of the active event with id eventId to newPriority.
  • int pollHighest() Removes and returns the eventId of the active event with the highest priority. If multiple active events have the same priority, return the smallest eventId among them. If there are no active events, return -1.

An event is called active if it has not been removed by pollHighest().

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class EventManager {
set<pair<int,int>> s;
unordered_map<int,int> e;
public:
EventManager(vector<vector<int>>& events) {
for(auto& event : events) {
s.insert({event[1], -event[0]});
e[event[0]] = event[1];
}
}

void updatePriority(int eventId, int newPriority) {
if(!e.count(eventId)) return;
s.erase({e[eventId], -eventId});
s.insert({newPriority, -eventId});
e[eventId] = newPriority;
}

int pollHighest() {
if(s.empty()) return -1;
int id = s.rbegin()->second;
s.erase(prev(end(s)));
e.erase(-id);
return -id;
}
};

/**
* Your EventManager object will be instantiated and called as such:
* EventManager* obj = new EventManager(events);
* obj->updatePriority(eventId,newPriority);
* int param_2 = obj->pollHighest();
*/
Author: Song Hayoung
Link: https://songhayoung.github.io/2026/09/04/PS/LeetCode/design-event-manager/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.