Linear time simple Python solution

  • 0
    class Solution(object):
        def maxRotateFunction(self, A):
            n= len(A)
            total, sum, max= 0, 0 , -100000000000000
            if(n==0): return 0
            for i in range(n):
                total+= i*A[i]
                sum+= A[i]
            for i in range(n):
                prev= total
                total+= (n*A[i] - sum)
                if(max < total):
                    max= total
            return max

Log in to reply

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