Work in sample input correctly but give wrong answer in hidden test case

#include
using namespace std;

int main() {

int n;
cin>>n;
while(n–){
int k;
cin>>k;
int a[k];
for(int i=0;i<k;i++){
cin>>a[i];
}
int cs=0;
for(int i=0;i<k;i++){
for(int j=i+1;j<k;j++){
int g=0;
int h=0;
int u=0;
int y=0;
for(int k=i;k<=j;k++){
if(a[k]>a[k+1]){
g++;
//decreasing check
}
if(a[k]<a[k+1]){
h++;
//increasing check
}
}
if(a[i]<a[i+1]){
u=g+h;
// check for first inc then dec
}
y=max(g,h);
y=max(u,y);
cs=max(cs,y);
}
}
cout<<cs<<endl;
}
}

Hi rajat
Save ur code to online ide of coding block and then post the link here

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.