Make a cut at different places and take the maximum of all
let max_val = 0 ; for ( let i = 1 ; i < n ; i ++ ) { max_val = Math . max ( max_val , Math . max ( i * ( n - i ) , maxProd ( n - i ) * i ) ) ; }