Easy to understand Python O(n) solution in 55ms


  • 0
    
        def maxRotateFunction(self, A):
            """
            :type A: List[int]
            :rtype: int
            """
            n = len(A)
            value = 0
            for i in range(n):
                value += i * A[i]
    
            max_value = value
    
            sumA = sum(A)
    
            for i in range(n):
                value = value + sumA - n*A[n-i-1]
                max_value = max(max_value, value)
    
            return max_value
    

Log in to reply
 

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