Wrong Anwer in TestCases

I am not getting the mistake in my code plz help me:
code:

using namespace std;
#include
int main()
{
int t;
cin>>t;
while(t–)
{
int n,count=0,max=0,inc=1;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];

	for(int i=1;i<n;i++)
	{
	//increasing then decreasing
		if(a[i]>=a[i-1] && inc==1)
		count++;
		
	//decreasing
		else if(a[i]<=a[i-1])
		{
			count++;
			inc=0;
		}
		
	//find another subarray;
		else
		{
			if(count>max)
			max=count;
			count=0,inc=1;
			--i;
		}
		
	}
	
	if(count>max)
	max=count;
	cout<<++max<<endl;
	
}

}

Your code logic is incorrect, if you do it this way then you have to consider every i as starting point which results in O(n*n) complexity,
technique is as follows:
we will maintain two array lets say dec and inc .
value at ith index of inc array will tell the longest increasing subarray ending at ith index.
value at ith index of dec array will tell u longest decreasing subbarray starting from ith index.
Now after constructing these two array we can answer this problem easily
we will iterate from i=0 to i=n-1 and store maximum value of inc[i]+dec[i]-1
I hope u find this helpful

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.