My issue: for n=5 how does the solution of author works?like suppose he said we only look for index divisible by 3 so 0 and 3 are such two index foir n=5 but how can we remove three indexs such that it is a aplindrome i.e we can remove index 1 and 2 but that equal to 3 so plz explain for n=5
My code
#include <iostream>
using namespace std;
#define ll long long
int main() {
int t;
cin >> t;
while(t--){
ll n,m,f1=0;
string s;
cin>>n>>s;
if(n%3==1) f1=1;
else{
for (char ch = 'a'; ch <= 'z'; ch++)
{
int r = n + 1, l = -1;
for (int i = 0; i < n; i++)
{
if (i % 3 == 0 && s[i] == ch)
{
r = i;
break;
}
}
for (int i = n - 1; i >= 0; i--)
{
int p = n - 1 - i;
if (p % 3 == 0 && s[i] == ch)
{
l = i;
break;
}
}
if (r < l)
{
f1 =1;
break;
}
}
}
if(f1) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}// your code goes here
Problem Link: BLAST3 Problem - CodeChef