Why this code isnt working for the solution

#include<bits/stdc++.h>
using namespace std;

bool palindrome(int a[],int n,int i,int j){
if(n==1 || n==0){
return true;
}

else if( a[i]==a[j] && palindrome(a,n,i+1,j-1))
{
	return true;
}
else 
return false;

}

int main(){
int n;
cin>>n;
int a[n]={0};
for(int i=0;i<n;i++){
cin>>a[i];
}
if(palindrome(a,n,0,n-1))
cout<<“true”;
else
cout<<“false”;
return 0;
}

Hello @gabbar_2229

You should pass n - 2 in the “else if( a[i]==a[j] && palindrome(a,n,i+1,j-1))” statement and NOT simply n.

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.