My code is passing sample cases but failing All Test Cases... Any Hint

This is my Code
include iostream
include algorithm
using namespace std;

//find first increasing than decreasing subarray
int fitdsa(int* arr, int n){

bool started = false;
bool decreasing = false;
int current_counter=0;
int max_count = 0;

for(int i=0; i<n; i++){
    if(arr[i]==1){
        if(!started){
            started=true;
            if(max_count<current_counter){
                max_count=current_counter;
            }
            current_counter=0;
            current_counter++;
        }
        if(started&&decreasing){
            started=true;
            decreasing=false;
            if(max_count<current_counter){
                max_count=current_counter;
            }
            current_counter=0;
            current_counter++;
        }
        if(started&&!decreasing){
            current_counter++;
        }
    }
    if(arr[i]==-1){
        if(decreasing&&started){
            current_counter++;
        }
        if(!decreasing&&started){
            current_counter++;
            decreasing=true;
        }
    }
    if(arr[i]==0){
        if(max_count<current_counter){
            max_count=current_counter;
        }
    current_counter=0;
    }
}
if(max_count<current_counter){
    max_count=current_counter;
}
return max_count;

}

int main(){
int t;
cin >> t;
while(t–){
int n;
cin>>n;
int* arr = new int[n];
int* idarr = new int[n];
int* diarr = new int[n];
for(int i=0; i<n; i++){
cin >> arr[i];
if(i==0){
idarr[i]=0;
diarr[i]=0;
}
else{
if(arr[i]>arr[i-1]){
idarr[i]=1;
diarr[i]=-1;
}
else if(arr[i]<arr[i-1]){
idarr[i]=-1;
diarr[i]=1;
}
else{
idarr[i]=0;
diarr[i]=0;
}
}
}

    int idmaxe = fitdsa(idarr, n); //Increasing Decreasing Max Element
    int dimaxe = fitdsa(diarr, n);
    int maxe = max(dimaxe, idmaxe);
    cout << maxe << endl;

    delete []diarr;
    delete []idarr;
    delete []arr;
}

return 0;

}

Please give me a minutes to look at your code

Hey @ajargrey You can solve the problem with much less lines of code and variables ,thus making it simpler to read and less prone to errors. Take a look at this c++ implementation https://ide.codingblocks.com/s/184439

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.