Bash Adjacent Elements Product
adjacent_elements_product() {
local -n _arr="$1"
local _max=-9223372036854775808
local _i _c=${#_arr[@]}
for ((_i = 0; _i < _c - 1; _i++)); do
local _p=$(( _arr[_i] * _arr[_i+1] ))
if (( _p > _max )); then _max=$_p; fi
done
echo "$_max"
}
This walks through neighboring values, multiplies each pair, and keeps the biggest product it finds.