Why is my code for question Bitonic sequences failing testcases

#include
using namespace std;
int main() {
int t;cin>>t;
for(int i=0;i<t;i++){
int n;cin>>n;int arr[n];
for(int j=0;j<n;j++){cin>>arr[j];}
if(n<3){cout<<n<<endl;}

	else{int x=0,diff=0;
		for(int y=1;y<n-1;y++){
			if(arr[y-1]>arr[y]&&arr[y]<arr[y+1]||arr[y]==arr[y-1]&&arr[y]<arr[y+1])
			{
				
				if(diff<(y-x+1)){diff=y-x+1;}
				x=y;
				}
		}

if(diff<(n-x)){diff=n-x;}
cout<<diff<<endl;
}
}
return 0;
}

the approach you are applying is wrong
what u re doing is at each instance i.e. each i you are checking if the previous element is greater and the next is greater as well or is they are equal and current is smaller than next
first you should use the right brackets always, here the precedence is okay so it works in some cases
this will not work because the condition previous is greater and next is greater only works when the sequence changes i.e. from decreasing to increasing without considering the current element
it skips this element in taking the account of it
what u need is this
first, you initialise a maxlen as 1 since 1 is the minimum possible answer
now u start a while loop for i=0 to n
first calculate the continuous ascent
followed by the descent
now u have to start from the last element of the descent
and at the end of each iteration update the maxlen
these two things are very important to consider
why this works in O(n) is simple if a[j] > a[j+1] it cannot simultaneously be a part of another biotonic string as a[j]<a[j+1] since that is contradictory so, only one pass is enough
if your doubt is solved kindly mark it as resolved