Recursion : dictionary order (small)

@chahatkumar It is given that the output must be in sorted order. You code will generate the correct permutations but it is not guaranteed that your output will be sorted. For that…instead of printing in base case…you must push it in a vector.You should then sort the resulting vector in the main before printing the final result.

In your code you were sorting it before the function call.

but if input is sorted ,the permutations should be sorted too
i commented the if condition and it is showing all the permutations in sorted order

Check output generated for bdca… it is not sorted. So sort the result only after the function call as i said earlier.

1 Like

okay thankyou :slight_smile:

i used the vector method
the code is working fine till i use the if condition in base case

also, if i use (o>s) as my if condition , all the permutations get printed

if(o>s) this type of comparison cannot be done with character arrays…or c style string.
This can only be done with string class.
if o and s were initilialized as string…this would work.

You can use if(strcmp(o,s)>0) here.

still not working :frowning_face:

What exactly is the issue? Test cases are not being passed or code is not compiling?

in case i use if condition : code gets compiled but no output is shown
if i dont use if condition : all the permutations are shown in sorted order

There is some issue with strcmp function.It is not working. Maybe with this compiler.
So instead use string class. The code would be much simple and you can directly compare strings.
Refer this:

1 Like

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.