Editorial's approach is wrong (weak testcases)


#1

I have a testcase on which the following code (Editorial’s code) throws wrong output

int Solution::solve(string A) {
    int i=0,n=A.size(),j=n-1, flag=0;
    while(j>=i){
        if(A[i]==A[j]){i++; j--;}
        else if(A[i]!=A[j] && flag==0){ 
            flag=1;  
            if(A[i+1]==A[j]){i++;}
            else  if(A[j-1]==A[i]){j--;}
            else if((j-i)==1){return 1;}
            else{return 0;}
            
        }
        else if(A[i]!=A[j] && flag==1){ return 0;}
    }
    return 1;
}

and the testcase is :

aaacbdbcbaaa
output should be 1 but it is giving 0

basically you have to completely check both the cases and that’s not the case with the code


#2

+1

you are correct. thanks for the test case!


#3

Output must be 0 in this test case …as it is not possible to convert this string into a palindrome by deleting only one character


#4

Just remove the aaacbdbc_b_aaa