Hello!
I am attempting this CSES Question
My solution:
#include <bits/stdc++.h>
using namespace std;
void reverse(string str)
{
for (int i=str.length()-1; i>=0; i–)
{
cout << str[i];
}
}
int main()
{
string str;
cin >> str;
vector all_permutations;
string permutations;
sort(str.begin() , str.end());
do{
all_permutations.push_back(str);
}while(next_permutation(str.begin() , str.end()));
for(int i = 0 ; i < all_permutations.size() ; i++)
{
if(all_permutations[i] == reverse(all_permutations[i]))
{
cout << all_permutations[i];
break;
}
else
{
cout << “NO SOLUTION”;
break;
}
}
}
I could find all permutations but it is not able to find which is the palindrome in it…and when i run it, it shows error
Please help