In the recently concluded NOV long contest, in the question PRPALN
I implemented a similar logic to the one in the editorial, but still was unable to solve it :
int i, j, t, len, flag;
string input;
cin>>t;
while(t--)
{
cin>>input;
len=input.length();
for(i=flag=0, j=len-1; i<=j; i++, j--)
{
if(input[i]==input[j]) continue;
else if(input[i+1]==input[j] && flag!=1)
{
flag=1; i++;
}
else if(input[i]==input[j-1] && flag!=1)
{
flag=1; j--;
}
else
{
flag=2; break;
}
}
if(flag!=2) cout<<"YES\n";
else cout<<"NO\n";
}
return 0;
Here is the submission link : Submission
Please help.