Bash Max Product Of Three
max_product_of_three() {
local -n _a="$1"
local -a _sorted=($(printf '%s\n' "${_a[@]}" | sort -n))
local _c=${#_sorted[@]}
local _p1=$(( _sorted[_c-1] * _sorted[_c-2] * _sorted[_c-3] ))
local _p2=$(( _sorted[0] * _sorted[1] * _sorted[_c-1] ))
if (( _p1 > _p2 )); then echo "$_p1"; else echo "$_p2"; fi
}
This checks the useful extremes, because the best product can come from either the three largest numbers or two negatives plus one large positive.