Not able to get the logic

Question : https://hack.codingblocks.com/app/contests/1289/394/problem

@vijayraghav18 you will be given a string and you have to print permutations of that string. But the only permutations that you have to print are the ones that would come AFTER that string if placed in a dictionary. For the given example, string is cab
all possible permutations are

abc
acb
bac
bca
cab
cba

as you can see, the only permutation that comes after “cab” is “cba” so that should be the output

I understood the question and also got the permutations which are greater than the given string but the problem is arranging the required permutations in lexicographical order

@vijayraghav18 you can generate all the permutations of the string and store them in a set (so they’ll be sorted automatically) then you can iterate over the set and print the reqd strings.
Alternatively, you can use the STL function next_permutation

In my code I had written the same code as that of permutations and changed the base case such that it gives only those permutations which are greater than given string ,so where should I write the set part

@vijayraghav18 in the base case, instead of printing the strings, insert the string in the set. You can make set a global variable or pass it by reference. Print the contents of the set in main function (after all permutations have been generated)

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.