i am not able to pass every testcase. can you please check my code
TRICKY PERMUTATIONS(hackers block)
@Ayushi21
As you can see your outputs are not in sorted order. The problem expects answers to be sorted in lexographic order. So try sorting them.
Make a vector of strings in global scope
vector < string > v;
Instead of printing the βansβ string in Line No. 8 , store this string in the vector using the push_back( ).
i.e. instead of the current Line No. 8 statement , write this
v.push_back(ans) ;
This will store all your output strings in the vector v and when your recursive calls are done , you will have a vector of strings in which your output strings are stored . Now the only thing we need to do is sort them.
So sort them using the sort( ) of < algorithm >
This is what your main( ) would look like :
int main( ) {
string input ;
cin >> input ;
printPermutationsNoDuplicates(input,"");
//after the recursive calls are done , your vector v declared in global is ready β¦ just sort it .
sort( v.begin() , v.end() ) ;
//Print the contents of vector v using a loop
return 0;
}
@Ayushi21
Modified code - https://ide.codingblocks.com/s/105078
You need not have removed the if condition in the recursive function.
Also you missed out on printing the final answer from the vector.