text: Maximize the sum of array after multiplying a prefix and suffix by | Kadane 's algorithm to find the maximum subarray sum ; Loop to find the maximum subarray array sum in the given array ; Function to find the maximum sum of the array by multiplying the prefix and suffix by - 1 ; Total intital sum ; Loop to find the maximum sum of the array ; Maximum value ; Driver Code
code: function maxSubArraySum ( a , size ) { var max_so_far = Number . MIN_VALUE , max_ending_here = 0 ; for ( i = 0 ; i < size ; i ++ ) { max_ending_here = max_ending_here + a [ i ] ; if ( max_ending_here < 0 ) max_ending_here = 0 ; if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; } return max_so_far ; } function maxSum ( a , n ) { var S = 0 ; var i ; for ( i = 0 ; i < n ; i ++ ) S += a [ i ] ; var X = maxSubArraySum ( a , n ) ; return 2 * X - S ; } var a = [ - 1 , - 2 , - 3 ] ; var n = a . length ; var max_sum = maxSum ( a , n ) ; document . write ( max_sum ) ;