My C++ solution, kindly suggest me improvements


#1

/**

  • @input A : Integer array
  • @input n1 : Integer array’s ( A ) length
  • @Output Integer
    */
    #include<math.h>
    #include<limits.h>
    int max(int a,int b)
    {
    if(a>b)
    return a;
    else
    return b;
    }

int min(int a,int b)
{
if(a<b)
return a;
else
return b;
}

int maxArr(int* A, int n1)
{
int max1 = INT_MIN;
int max2 = INT_MIN;
int min1 = INT_MAX;
int min2 = INT_MAX;
int i = 0;
for(i = 0;i<n1;i++)
{
max1 = max(max1,A[i] + i);
min1 = min(min1,A[i] + i);
max2 = max(max2,A[i] - i);
min2 = min(min2,A[i] - i);
}
return max(max1 - min1, max2 - min2);
}


#2

U want improvements!!
Here,I’ve got one.You can use min and max functions of math.h library if you want to these functions in your code are unnecessary taking space and doesn’t even look good for someone who is checking out solutions.


#3

I learned about min and max months later after submitting the solution, still thanks!