Find maximum value of Sum ( i * arr [ i ] ) with only rotations on given array allowed | returns max possible value of Sum ( i * arr [ i ] ) ; stores sum of arr [ i ] ; stores sum of i * arr [ i ] ; initialize result ; try all rotations one by one and find the maximum rotation sum ; return result ; test maxsum ( arr ) function
def maxSum ( arr ) : NEW_LINE INDENT arrSum = 0 NEW_LINE currVal = 0 NEW_LINE n = len ( arr ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT arrSum = arrSum + arr [ i ] NEW_LINE currVal = currVal + ( i * arr [ i ] ) NEW_LINE DEDENT maxVal = currVal NEW_LINE for j in range ( 1 , n ) : NEW_LINE INDENT currVal = currVal + arrSum - n * arr [ n - j ] NEW_LINE if currVal > maxVal : NEW_LINE INDENT maxVal = currVal NEW_LINE DEDENT DEDENT return maxVal NEW_LINE DEDENT arr = [ 10 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] NEW_LINE print " Max ▁ sum ▁ is : ▁ " , maxSum ( arr ) NEW_LINE