Easy C++ solution using two vector of A[x]+x and A[x]-x


#1

int Solution::maxArr(vector &a1)
{

vector b;
vector b1;
int count1 = 1;
for(auto x=a1.begin(); x!= a1.end(); x++)
{
count1++;
b.push_back(*x - count1);
// cout<<b[count1-1]<<endl;
}

int count2 = 1;
for(auto x=a1.begin(); x!= a1.end(); x++)
{
count2++;
b1.push_back(*x + count2);
// cout<<b[count1-1]<<endl;
}

int max1= *max_element(b.begin(),b.end());
int min1 = *min_element(b.begin(),b.end());

int max2= *max_element(b1.begin(),b1.end());
int min2 = *min_element(b1.begin(),b1.end());
int ans1 = max1-min1;
int ans2 = max2-min2;
if(ans2>=ans1)
{
return ans2;
}

return ans1;

}