Code not working for some cases
hi @mandeepchohan96, you are computing the length of increasing and decreasing sequence length for every index in lengthy way as you compute them in O(n) due to this you are getting time limit error also , the length of biotonic sequence is (listD[i]+listI[i]-1 ) instead of (listD[i]+listI[i]) as you are considering A[i] in both listD[i],listI[i] this causes wrong answer.
refer below code :-
int biotonic (int a[],int n)
{
int inc[n],dec[n];
inc[0]=1;
dec[n-1]=1;
for(int i=1;i<n;i++)
inc[i]=(a[i]>=a[i-1])?inc[i-1]+1:1;
for(int i=n-2;i>=0;i--)
dec[i]=(a[i]>=a[i+1])?dec[i+1]+1:1;
int max=inc[0]+dec[0]-1;
for(int i=1;i<n;i++)
{//-1 is done to remove the element which counted double in both the array
int t=inc[i]+dec[i]-1;
if(t>max)
max=t;
}
return max;
}
In case of any doubt feel free to ask 
If you got the answer then mark your doubt as resolved
1 Like