Java | sort | sweep line | no DP or BST or TreeMap
Solution 1 --  sweep line\n\nclass Solution {\n    public int maxTwoEvents(int[][] events) {\n        List<int[]> list = new ArrayList<>();\n        for(int i =
Solution 1 --  sweep line\n```\nclass Solution {\n    public int maxTwoEvents(int[][] events) {\n        List<int[]> list = new ArrayList<>();\n        for(int i = 0; i < events.length; ++i) {\n            int[] arrStart = new int[]{events[i][0], 1, events[i][2]};           //  {startTime, 1, value}\n            int[] arrEnd = new int[]{events[i][1] + 1, 0, events[i][2]};         //  {endTime + 1, 0, value}  (+1 for exclusive)\n            list.add(arrStart);\n            list.add(arrEnd);\n        }\n        \n        Collections.sort(list, (a, b) -> a[0] == b[0] ? a[1] - b[1] : a[0] - b[0]);   //sort by timstamp. if same, put startTime before endTime..\n        \n        int maxSoFar = 0, maxRes = 0;\n        for(int j = 0; j < list.size(); ++j) {\n            if(list.get(j)[1] == 1)    //startTime\n                maxRes = Math.max(maxRes, maxSoFar + list.get(j)[2]);\n            else      //endTime\n                maxSoFar = Math.max(maxSoFar, list.get(j)[2]);\n        }\n        return maxRes;\n    }\n}\n```\n\nsolution2 --  TreeMap\n\n```\nclass Solution {\n    public int maxTwoEvents(int[][] events) {\n        Arrays.sort(events, (a, b) -> a[1] - b[1]);\n        TreeMap<Integer, Integer> map = new TreeMap<>(){{put(0, 0);}};\n        \n        int maxP = 0;\n        for(int[] event : events) {\n            maxP = Math.max(maxP, event[2] + map.lowerEntry(event[0]).getValue());\n            \n            int hi = Math.max(event[2], map.lastEntry().getValue());\n            map.put(event[1], hi);\n        }\n        \n        return maxP;\n    }\n}
[]