GO | Binary Search On End Date
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```golang []\nfunc maxTwoEvents(events [][]int) int {\n\tlength := len(events)\n\tsort.Slice(events, func(i, j int) bool {\n\t\treturn events[i][0] < events[j][0]\n\t})\n\n\tmaxValueAtIndex := make([]int, length)\n\tmaxValue := math.MinInt32\n\tfor idx := length - 1; idx >= 0; idx-- {\n\t\tmaxValue = max(maxValue, events[idx][2])\n\t\tmaxValueAtIndex[idx] = maxValue\n\t}\n\n\tmaxSum := 0\n\tfor idx := 0; idx < length; idx++ {\n\t\tcurrEventEnd := events[idx][1]\n\t\tcurrEventValue := events[idx][2]\n\n\t\tnextEventStart := currEventEnd + 1\n\t\tnextEventIndex := binarSearch(nextEventStart, events)\n\n\t\tcurrSum := currEventValue\n\t\tif nextEventIndex < length {\n\t\t\tcurrSum += maxValueAtIndex[nextEventIndex]\n\t\t}\n\t\tmaxSum = max(maxSum, currSum)\n\t}\n\n\treturn maxSum\n}\n\nfunc binarSearch(val int, arr [][]int) int {\n\tlow, high := 0, len(arr)-1\n\n\tresultIndex := high + 1\n\tfor low <= high {\n\t\tmid := low + ((high - low) / 2)\n\t\tif arr[mid][0] >= val {\n\t\t\tresultIndex = mid\n\t\t\thigh = mid - 1\n\t\t} else if arr[mid][0] < val {\n\t\t\tlow = mid + 1\n\t\t}\n\t}\n\n\treturn resultIndex\n}\n```
['Go']