Time out problem. Please help to figure out the mistake

int Solution::maxArr(vector &A) {
int n=A.size()-1;
int ans = abs(A[0]-A[n])+abs(n-0);
for(int i=0; i<n; i++){
for(int j=n; j>i; j–){
int sum = abs(A[i]-A[j])+abs(j-i);
ans = max(ans, sum);
}
}
return ans;

}

time complexity of your solution is O(n*n)

Click here to start solving coding interview questions