How to optimize this? The time limit is exceeding for the solution.


  • 0
        public int maxRotateFunction(int[] A) {
             int n=A.length;
             int max=0;
             
            for(int j=0;j<n;j++){
                max=max+A[j]*j;
            }
            
            for(int i=0;i<n;i++) {
                int sum=0;
                for(int k=0;k<n;k++)
                    sum=sum+A[k]*((i+k)%n);
                
    
                if(sum>max)
                    max=sum;
            }
            
            
            return max;
        }
    }```

Log in to reply
 

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