Sir why,if my code is wrong please correct it

#include
using namespace std;

int max_len(int a[],int n){

int i=0;
int M=0;

while(i+1<n){
    int len=1;
    while(i+1<n and a[i]<a[i+1]){
        i++;
        len++;
    }
    while(i+1<n and a[i]>a[i+1]){
        i++;
        len++;
    }
    M=max(M,len);
}
return M;

}
int main() {

int T;
cin>>T;
while(T--){
    int a[1000000];
    int n;
    cin>>n;
    
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    cout<<max_len(a,n)<<endl;
}


return 0;

}

@Harshit-Kumar-2577121455897279
you are only checking greater or smaller elements. You also have to consider equal elements
example
1
5
1 1 1 1 1
ans should be “5” not “1”

@Harshit-Kumar-2577121455897279
Also consider this testcase
1
11
40 30 20 10 10 10 20 30 40 20 10
Ans should be 8 (10 10 10 20 30 40 20 10)

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.