Pre Computation + Binary Search || O(n log n) || time better than 93.92% & space 88%
\nclass Solution {\n    public int maxTwoEvents(int[][] events) {\n        Arrays.sort(events,(a,b)->a[0]-b[0]);\n        int ans=0;\n        int n=events.lengt
```\nclass Solution {\n    public int maxTwoEvents(int[][] events) {\n        Arrays.sort(events,(a,b)->a[0]-b[0]);\n        int ans=0;\n        int n=events.length;\n        int[] maxVal=new int[n];\n        maxVal[n-1]=events[n-1][2];\n        for(int i=n-2;i>=0;i--)\n            maxVal[i]=Math.max(maxVal[i+1],events[i][2]);\n            \n        for(int i=0;i<n;i++){\n            int cur=events[i][2];\n            int ind=binarySearch(events,events[i][1],i+1);\n            if(ind<n)\n                cur+=maxVal[ind];\n            ans=Math.max(ans,cur);\n        }\n        \n        return ans;\n    }\n    \n    int binarySearch(int[][] events,int num,int low){\n        int ans=events.length;\n        int high=events.length-1;\n        while(low<=high){\n            int mid=(low+high)/2;\n            if(events[mid][0]>num){\n                ans=mid;\n                high=mid-1;\n            }else\n                low=mid+1;\n        }\n        return ans;\n    }\n}\n```
['Binary Search', 'Java']