Can anybody tell why I am getting TLE? My solution is pretty similar to the one given in approach but still im getting TLE


#1

bool belongsto(char i)
{
if( (i >= 65 and i<=90) or (i>=97 and i<=122) or (i>=48 and i<=57))
{
return true;
}
return false;
}

bool caseconvertcompare(int i, int j, string A)
{
if(A[i]>=97 and A[i]<=122)
{
A[i] = A[i]-32;
}
if(A[j]>=97 and A[j]<=122)
{
A[j] = A[j]-32;
}
if(A[i]==A[j])
{
return true;
}
return false;
}

int Solution::isPalindrome(string A) {
int l = A.length();
int i=0, j=l-1;
// cout<<“len : “<<l<<endl;
// cout<<A[i]<<”–”<<A[j]<<endl;
while(i<j)
{
while(!belongsto(A[i]) and i<j)
{
i++;
}
if(i==l-1)
{
return 1;
}
while(!belongsto(A[j]) and j>1)
{
j–;
}
if(j==0)
{
return 1;
}
// cout<<i<<"–"<<j<<endl;
if(i>j)
{
return 1;
}
else if(!caseconvertcompare(i,j,A))
{
return 0;
}
i++;
j–;
}
return 1;
}


#2

Got it im doing a lot of processing like not using isalnum and also not directly using toupper