Simplest solution c++ O(n)


#1

int Solution::solve(string A) { int l=0,r=A.length()-1; int cnt=0; while(l<=r) { if(A[l]!=A[r]){ cnt++; l++;} else { l++,r--; } } if(cnt<2) return 1; return 0; }


#2

try with “aeaddaeba”
your return value is 0 but it should be 1… because if we remove b from 2nd last position we will get palindrome…give your view…please


#3

Similar approach, but with corner cases checked.

int Solution::solve(string A) {
    int left = 0;
    int right = A.size()-1;
    int count = 0;
    while(left<right)
    {
        if(A[left]==A[right]){left++;right--;}
        else if(A[left+1]==A[right]){count++;left++;}
        else if(A[left]==A[right-1]){count++;right--;}
        else return 0;
    }
    if(count == 0 and left == right) return 1;
    if(count == 1) return 1;
    return 0;
}