Bitonic SubArray Length, Sample test cases are working but not the hidden ones

int bitonic(int a[],int N)
{
int inc[N],dec[N],m,i;
inc[0]=1;
dec[N-1]=1;
for(i=1;i<N;i++)
{
inc[i]=(a[i]>=a[i-1])?inc[i-1]+1:1;
}
for(i=N-2;i>=0;i–)
{
dec[i]=(dec[i]>=dec[i+1])?dec[i+1]+1:1;
}
m=inc[0]+dec[0]-1;
for(i=1;i<N;i++)
{
if((inc[i]+dec[i]-1)>m)
{
m=inc[i]+dec[i]-1;
}
}
return m;
}

while creating the dec array you are comparing dec[i] with dec[i+1] but you should compare a[i] with a[i+1]

1 Like