Java PriorityQueue solution
\n# Code\n\nclass Solution {\n    public int maxTwoEvents(int[][] events) {\n        int res = 0, maxVal = 0;\n        //Min heap by ending time\n        Priori
\n# Code\n```\nclass Solution {\n    public int maxTwoEvents(int[][] events) {\n        int res = 0, maxVal = 0;\n        //Min heap by ending time\n        PriorityQueue<int[]> pq = new PriorityQueue<>(Comparator.comparingInt(a -> a[0]));\n        //Sort the array by start time\n        Arrays.sort(events, Comparator.comparingInt(a -> a[0]));\n        for (int[] e : events) {\n            //Pop all the finished events and maintain maximum value till now\n            while (!pq.isEmpty() && pq.peek()[0] < e[0]) {\n                maxVal = Math.max(maxVal, pq.poll()[1]);\n            }\n            //Check for max value\n            res = Math.max(res, maxVal + e[2]);\n            pq.offer(new int[]{e[1], e[2]});\n        }\n        return res;\n    }\n}\n```
['Java']