Tricky permutation problem

last test case not execute
#include<bits/stdc++.h>
using namespace std;
vector v;
bool compare(string a,string b){
return a<b;
}
void permutation(char *input,int i){
if(input[i]==’\0’){
bool flag=false;
for(int i=0;i<v.size();i++){
if(v[i].compare(input)==0){
flag=true;
break;
}
}
if(!flag)
v.push_back(input);
return;
}
for(int j=i;input[j]!=’\0’;j++){
swap(input[i],input[j]);
permutation(input,i+1);
swap(input[i],input[j]);
}
}
int main() {
char ch[9];
cin>>ch;
permutation(ch,0);
sort(v.begin(),v.end(),compare);
for(int i=0;i<v.size();i++){
cout<<v[i]<<endl;
}
v.clear();
return 0;
}

hey @priyamkr, you can directly push the answer in vector without using this flag and compare.
I have made changes to your own code only, you can check it. https://ide.codingblocks.com/s/86087

hey @priyamkr , if no further query,please mark this doubt as resolved.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.