1
var maxTwoEvents = function (events) {
2
const n = events.length;
3

4
events.sort((a, b) => a[0] - b[0]);
5

6
const minHeap = new MinPriorityQueue({ priority: (x) => x[1] });
7

8
let maxVal = 0;
9
let maxSum = 0;
10

11
for (let i = 0; i < n; ++i) {
12
const [currStart, currEnd, currVal] = events[i];
13

14
while (!minHeap.isEmpty()) {
15
const topElement = minHeap.front().element;
16
const [topIdx, topEnd] = topElement;
17

18
if (topEnd < currStart) {
19
maxVal = Math.max(maxVal, events[topIdx][2]);
20
minHeap.dequeue();
21
} else {
22
break;
23
}
24
}
25

26
const sum = maxVal + currVal;
27
maxSum = Math.max(maxSum, sum);
28
minHeap.enqueue([i, currEnd]);
29
}
30

31
return maxSum;
32
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0