Kotlin || Binary Search
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```kotlin []\nclass Solution {\n    private fun isOverlapping(a: IntArray, b: IntArray): Boolean {\n        return  !(a[1] < b[0] || b[1] < a[0])\n    }\n\n    private fun nextNonOverlappingIndex(events: Array<IntArray>, i: Int): Int {\n        var l = i + 1\n        var r = events.size - 1\n        while (l < r) {\n            val m = l + (r - l) / 2\n            if (isOverlapping(events[i], events[m])) {\n                l = m + 1\n            } else {\n                r = m\n            }\n        }\n        return l\n    }\n\n    fun maxTwoEvents(events: Array<IntArray>): Int {\n        events.sortBy { it[0] }\n\n        val maxValues = mutableListOf<Int>()\n        for (i in events.indices.reversed()) {\n            if (maxValues.isEmpty()) {\n                maxValues.add(events[i][2])\n            } else {\n                maxValues.add(maxOf(events[i][2], maxValues.last()))\n            }\n        }\n        maxValues.reverse()\n\n        var ans = 0\n        for (i in events.indices) {\n            ans = max(ans, events[i][2])\n            val j = nextNonOverlappingIndex(events, i)\n            if (j < events.size && !isOverlapping(events[i], events[j])) {\n                ans = max(ans, events[i][2] + maxValues[j])\n            }\n        }\n        return ans\n    }\n}\n```
['Binary Search', 'Kotlin']