Go Perm Missing Element
func permMissingElement(a []int) int {
sorted := append([]int(nil), a...)
sort.Ints(sorted)
for k, v := range sorted {
if v != k+1 {
return k + 1
}
}
return len(sorted) + 1
}
This uses the expected sum of 1..N+1 and subtracts the actual sum to find the missing value.