NOTE:i am trying to do this only for one testcase only, so, i didn’t added loop for testcase.
Still i am stuck here, and not getting what to do now.
Doubt in maximum length biotonic subarray
Hello @shubham.mehla2000,
There are few mistakes in your code:
for(int k=i;k<n;k++) , iterating it for all values will cause wrong answer due to following code:
int d=a[k+1]-a[k];
for k=n-1, a[k-1]=a[n] // due to out of bound index, it will return a junk value.
Solution:
int length=1; //make this change also.
for(int k=i;k<n-1;k++)
the following code is causing wrong output for testcases like:
6
1 1 1 1 1 1
Expected output:
6
Solution:
Remove the following code:
if(d==0)
{
f=1;
break;
}
Once you’ll iterarte for decreasing sequence, the gu will become 1.
And it will 1 for all the values of i.
Solution:
int length=1;
int gu=0;// add this before inner for loop.
Hope, this would help.
Give a like, if you are satisfied.
best explanation till now (all doubts just solved in one reply only)!
thankyou very much sir!!!1
just one thing sir.
should i try this question by dynamic memory alloction also???
You should if you want to.
As you are in learning stage. So, it will help in better understanding of the concept.
BTW, mark the doubt as resolved.