Maximum sum of i * arr [ i ] among all rotations of a given array | Returns maximum value of i * arr [ i ] maximum sum rotation ; Initialize result ; Consider rotation beginning with i for all possible values of i . ; Initialize sum of current rotation ; Compute sum of all values . We don 't  actually rotation the array, but compute  sum by finding ndexes when arr[i] is  first element ; Update result if required ; Driver code
function maxSum ( arr , n ) { var res = Number . MIN_VALUE ; for ( i = 0 ; i < n ; i ++ ) { var curr_sum = 0 ; for ( j = 0 ; j < n ; j ++ ) { var index = ( i + j ) % n ; curr_sum += j * arr [ index ] ; } res = Math . max ( res , curr_sum ) ; } return res ; } var arr = [ 8 , 3 , 1 , 2 ] ; var n = arr . length ; document . write ( maxSum ( arr , n ) ) ;