Bash Perm Missing Element
perm_missing_element() {
    local -n _a="$1"
    local -a _sorted=($(printf '%s\n' "${_a[@]}" | sort -n))
    local _k
    for _k in "${!_sorted[@]}"; do
        if (( _sorted[_k] != _k + 1 )); then
            echo $(( _k + 1 ))
            return
        fi
    done
    echo $(( ${#_sorted[@]} + 1 ))
}

This uses the expected sum of 1..N+1 and subtracts the actual sum to find the missing value.