Maximum length biotonic subarray

I am not able to solve this problem.

You can basically take two arrays, one as : int inc[1000000] and other as int dec[1000000], and then you will calculate the values on both the arrays based on wheather the sequence is increasing or sequence is decreasing, thus you will have, initial values as ,
inc[0]=1;
dec[n-1]=1;
Thus, you will traverse the array and calculate the values, as :
if(ar[i]>=ar[i-1])
{
inc[i]=inc[i-1]+1;
}
else
{
inc[i]=1;
}
Similarly, for dec[i] also, similar values will be calculated, and then you will take maximum value as,
max=inc[0]+dec[0]-1;
and then you will traverse the array again, and check,
if((inc[i]+dec[i]-1)>max)
{
max=inc[i]+dec[i]-1;
}
The maximum value thus calculated will be your final answer…