➤ Problem Link : AMR12D
👉 Hint : Use unordered_set
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
unordered_set<string> st;
int main()
{
int t;
cin>>t;
while(t--)
{
st.clear();
string s;
bool flag=1;
cin>>s;
string t;
for(int i=0;i<s.length();i++)
{
t="";
for(int j=i;j<s.length();j++)
{
t+=s[j];
st.insert(t);
}
}
for(int i=0;i<s.length();i++)
{
t="";
for(int j=i;j<s.length();j++)
{
t+=s[j];
string p=t;
reverse(p.begin(),p.end());
if(st.find(p)==st.end())
{
flag=0;
break;
}
}
if(flag==0)
break;
}
if(!flag)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
}
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!
