PKSODRJ6G6T27G4GUDITY4KT5B5DBY2HUNGFDXY2MOMZS67VIANAC
func SolveSecond(data []int, invalid int) (int, error) {
for i, d := range data {
var sum = d
var min, max = d, d
for j := i + 1; j < len(data); j++ {
sum += data[j]
if data[j] < min {
min = data[j]
}
if data[j] > max {
max = data[j]
}
if sum == invalid {
return min + max, nil
}
if sum > invalid {
break
}
}
}
return 0, fmt.Errorf("sum for invalid not found")
}