The overall max sum is the sum of both parts minus the peak element , because it was counted twice .
let sum_all = sum_inc + sum_dec - arr [ j ] ; max_sum = Math . max ( Math . max ( max_sum , sum_inc ) , Math . max ( sum_dec , sum_all ) ) ;