My issue
My code
#include <iostream>
using namespace std;
bool is_palin(string& s, int start, int end) {
while (start < end) {
if (s[start] != s[end])
return false;
start++;
end--;
}
return true;
}
bool solve(int i,string &s){
if(i>=s.size()) return false;
if(is_palin(s,0,s.size()-1)) return true;
bool no=solve(i+1,s);
string str;
for(int j=0;j<s.size();j++){
if(j==i||j==i-1||j==i+1) continue;
str.push_back(s[j]);
}
bool yes=solve(1,str);
return no||yes;
}
int main() {
int t; cin>>t;
while(t--){
int n; cin>>n;
string s; cin>>s;
unordered_map<int,string>
if(solve(1,s)) cout<<"YES"<<endl;
else{
cout<<"NO"<<endl;
}
}
return 0;
}
Problem Link: BLAST3 Problem - CodeChef