Test cases are failing

CODE : https://ide.codingblocks.com/s/252749
QUESTION : https://hack.codingblocks.com/app/contests/1289/394/problem

for input
abc
your ouput
bac
bca
cab
cba

best and easy way to solve this is using next_permutation()
code

Is there no correction for my code

I had to write code using recursion

if you want to do it using STL
The idea is based on the following facts:

  1. An sequence sorted in descending order does not have next permutation. For example edcba” does not have next permutation.
  2. For a sequence which is not sorted in descending order for example “abedc”, we can follow below steps.
    ……….a) Traverse from right and find the first item that is not following the descending order. For example in “abedc”, the character ‘b’ does not follow the descending order.
    ……….b) Swap the found character with closest greater (or smallest greater) element on right side of it. In case of “abedc”, we have ‘c’ as the closest greater element. After swapping ‘b’ and ‘c’, string becomes “acedb”.
    ……….c) After swapping, sort the string after the position of character found in step a . After sorting the substring “edb” of “acedb”, we get “ acbde ” which is the required next permutation.

Optimizations in step b) and c)
a) Since the sequence is sorted in decreasing order, we can use binary search to find the closest greater element.
c) Since the sequence is already sorted in decreasing order (even after swapping as we swapped with the closest greater), we can get the sequence sorted (in increasing order) after reversing it.

Code

I am not able to understand your logic conyou please explain in a simpler way

this is simpler explanation
for now you can ignore optimizations

can you tell me in which portion you are facing problem?
i will try to help

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.