Skip to content

Instantly share code, notes, and snippets.

@maxclav
Last active August 5, 2023 04:50
Show Gist options
  • Save maxclav/37b321d749ccc8d5cc18d65aa982a2b3 to your computer and use it in GitHub Desktop.
Save maxclav/37b321d749ccc8d5cc18d65aa982a2b3 to your computer and use it in GitHub Desktop.
Kadane's Algorithm in Go (GoLang).
package array
func maxSubArraySum(a []int, size int) int {
maxSoFar, currMax := a[0], a[0]
for i := 1; i < size; i++ {
currMax = max(a[i], currMax + a[i])
maxSoFar = max(maxSoFar, currMax)
}
return maxSoFar
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment