Minimal understandable C++ code


#1
 int n = s.length();
int i =0 ;
int j =n-1;
int count=0;
while (i<=j & i<n &j<n)
{
    if ( s[i]==s[j] ) // for equal condition
    {
        
        i++;
        j--;
    }
    else // for not equal condition
    {
        if ( s[i+1]==s[j])
        {
            i++;
            count++;
        }
        else if ( s[i]==s[j-1])
        {
            j--;
            count++;
        }
        else 
        {
            return 0;
        }
    }
}
if (count>1)
{
    return 0;
}
else 
{
    return 1;
}

}


#2

This will fail for “baaba”


#3

Brother, my code is almost identical to urs code. Coincidence…


#4

It will not. It will return 1.


#5
 int n = s.length();
int i =0 ;
int j =n-1;
int count=0;
while (i<=j & i<n &j<n)
{
    if ( s[i]==s[j] ) // for equal condition
    {
        
        i++;
        j--;
    }
    else // for not equal condition
    {
        if ( s[i+1]==s[j])
        {
            i++;
            count++;
        }
        else if ( s[i]==s[j-1])
        {
            j--;
            count++;
        }
        else 
        {
            return 0;
        }
    }
}
if (count>1)
{
    return 0;
}
else 
{
    return 1;
}
```(If this is ur code)It returned 0 when I tested.Please check once again