I have solved the problem with O(n^2) which is not best. But my program fails on the following test case :

[2147483647,2147483647]

I have used this as a custom test case and run the code. It gives the result as expected:

Your input

[2147483647,2147483647]

Your answer

2147483647

Expected answer

2147483647

Here is my code:

```
class Solution {
int calculateF(vector<int>& B)
{
static int j = 0;
int maxval = 0;
int totalCount = B.size();
for(int i = 0; i < totalCount; i++)
maxval += ((totalCount - j + i) % totalCount)*B[i];
j++;
return maxval;
}
public:
int maxRotateFunction(vector<int>& A) {
int max = INT_MIN;
int totalCount = A.size();
if (totalCount == 0) return 0;
for (int i = 0; i <totalCount;i++)
{
int calc = calculateF(A);
max = max < calc ? calc:max;
}
return max;
}
};
```

Do you anyone have any idea why it fails?