Skip to content

Instantly share code, notes, and snippets.

@sahajre
Last active August 7, 2019 13:38
Show Gist options
  • Save sahajre/87614f5f08b250a2c9cb978ad4a44844 to your computer and use it in GitHub Desktop.
Save sahajre/87614f5f08b250a2c9cb978ad4a44844 to your computer and use it in GitHub Desktop.
package msp
func mspN3(n []int) (maxSum, mi, mj int) {
l := len(n)
if l == 0 {
return -1, -1, -1
}
maxSum = n[0]
for i := 0; i < l; i++ {
for j := i; j < l; j++ {
sum := 0
for k := i; k <= j; k++ {
sum += n[k]
if sum > maxSum {
maxSum = sum
mi = i
mj = k
}
if sum == maxSum {
mj = k
}
}
}
}
return maxSum, mi, mj
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment