Golang Easy solutions
\n\n# Code\ngolang []\nimport (\n\t"sort"\n)\n\nfunc maxTwoEvents(events [][]int) int {\n\t// Step 1: Sort events by their end times\n\tsort.Slice(events, func(
\n\n# Code\n```golang []\nimport (\n\t"sort"\n)\n\nfunc maxTwoEvents(events [][]int) int {\n\t// Step 1: Sort events by their end times\n\tsort.Slice(events, func(i, j int) bool {\n\t\treturn events[i][1] < events[j][1]\n\t})\n\n\tn := len(events)\n\tmaxValues := make([]int, n)\n\tmaxValues[0] = events[0][2] // Value of the first event\n\n\t// Fill the running max array\n\tfor i := 1; i < n; i++ {\n\t\tmaxValues[i] = max(maxValues[i-1], events[i][2])\n\t}\n\n\tmaxSum := 0\n\n\t// Step 3: Iterate through the events and use binary search\n\tfor i := 0; i < n; i++ {\n\t\tstart := events[i][0]\n\t\tvalue := events[i][2]\n\n\t\t// Find the latest event that ends before the current event starts\n\t\tidx := binarySearch(events, start-1)\n\n\t\tcurrentSum := value\n\t\tif idx != -1 {\n\t\t\tcurrentSum += maxValues[idx]\n\t\t}\n\n\t\tmaxSum = max(maxSum, currentSum)\n\t}\n\n\treturn maxSum\n}\n\n// Helper: Binary search to find the latest event that ends <= targetEnd\nfunc binarySearch(events [][]int, targetEnd int) int {\n\tstart, end, res := 0, len(events)-1, -1\n\n\tfor start <= end {\n\t\tmid := start + (end-start)/2\n\t\tif events[mid][1] <= targetEnd {\n\t\t\tres = mid\n\t\t\tstart = mid + 1\n\t\t} else {\n\t\t\tend = mid - 1\n\t\t}\n\t}\n\n\treturn res\n}\n\n// Utility: Max function\nfunc max(a, b int) int {\n\tif a > b {\n\t\treturn a\n\t}\n\treturn b\n}\n```
['Go']