Maximize the sum of arr [ i ] * i | JavaScript program to find the maximum value of i * arr [ i ] ; Sort the array ; Finding the sum of arr [ i ] * i ; Driver Code
function maxSum ( arr , n ) { arr . sort ( ) ; let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum += ( arr [ i ] * i ) ; return sum ; } let arr = [ 3 , 5 , 6 , 1 ] ; let n = arr . length ; document . write ( maxSum ( arr , n ) ) ;