Maximize array sum by replacing equal adjacent pairs by their sum and X respectively | Function to calculate x ^ y ; Base Case ; Find the value in temp ; If y is even ; Function that find the maximum possible sum of the array ; Print the result using the formula ; Driver Code ; Function Call
function power ( x , y ) { var temp ; if ( y == 0 ) return 1 ; temp = power ( x , parseInt ( y / 2 ) ) ; if ( y % 2 == 0 ) return temp * temp ; else return x * temp * temp ; } function maximumPossibleSum ( N , X ) { document . write ( X * ( power ( 2 , N ) - 1 ) ) ; } var N = 3 , X = 5 ; maximumPossibleSum ( N , X ) ;