Dictionary Order (Recursion Challenges)

The code showing wrong output on submission :frowning:

your code is not correct
at line no 18 before swapping and recursion call
this condition will not give correct output
instead you have to check in base case that whether the current permutation is larger than original string or not

Modified Code

1 Like

Hey man!!
I think what I’ve written makes sense.
Coz if you think abt it,
(i) For the positions smaller than ‘i’ : The fact that we’ve reached i means that all of them were larger or same valued wrt to a[i].
(ii) For the positions larger than ‘i’ : If a[j] is larger than a[i], then it will surely result in lexicographically higher position and if it is equal, it might end up in a lexicographically higher position and that’ll be checked by us in the following recursions.

No no never mind
I got it

Thank you so much !!

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.

1 Like