Simple Python Solution

  • 0
    def maxRotateFunction(self, A):
            vector_sum = sum(A)
            length =len(A)
            last = 0
            for i in range(0, length):
                last += A[i] * i
            max_so_far = last
            for i in range(1, length):
                last = last + vector_sum - length * A[-i]
                max_so_far = max(max_so_far, last)
            return max_so_far

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.