Hi i was doing IsPalindrome challenge and coding blocks’ ide is throwing an error whereas, the same code is running fine on other platform.
Please help me out with this
Run time error is IsPalindrome
Hey @vanya.garg
#include<iostream>
#include<cstring>
using namespace std;
bool palindrome (int str[], int start, int last) //collecting as int array
{
if(start>=last)return true;//added this base case
int flag = 1;
if (str[start]==str[last]){
start++;
last--;
flag=palindrome (str, start, last); //update flag
}
else {
flag = 0;
// exit;why exit
}
if (flag == 1){
return true;
}
else return false;
}
int main()
{
int s[1001];//take integer array since input is integer they can be more than a single digit
int n;
cin>>n;
for (int i=0; i<n; i++){
cin>>s[i];
}
if (palindrome(s, 0, n-1)){
cout<<"true";
}
else cout<<"false";
}