Go Max Slice Sum
func maxSliceSum(a []int) int {
tmp, best := math.MinInt, math.MinInt
for _, v := range a {
if tmp+v > v {
tmp += v
} else {
tmp = v
}
if tmp > best {
best = tmp
}
}
return best
}
This is a Kadane-style scan: keep the best running sum and the best overall sum while moving once through the array.