#K55602. Lexicographically Greater Permutations
Lexicographically Greater Permutations
Lexicographically Greater Permutations
Given a string s consisting of lowercase alphabets, find all the unique permutations that are lexicographically greater than s. The results should be printed in ascending lexicographical order. If there are no such permutations, the output is empty.
Note: The comparison between strings is based on the standard lexicographical order. For example, if s = "abc", then the valid permutations are acb, bac, bca, cab, cba.
The formula to compare two strings a and b in lexicographical order can be understood as:
$$\text{For two strings } a \text{ and } b, \text{ we have } a < b \iff \exists\, i \text{ such that } a_i < b_i \text{ and } a_j = b_j \text{ for all } j < i. $$inputFormat
Input is given from standard input. It consists of a single string s in one line, where s is comprised of lowercase alphabetical characters.
Example:
abc
outputFormat
Output all lexicographically greater unique permutations of the given string, each printed in a new line in ascending order. If no valid permutation exists, output nothing.
Example (corresponding to the input above):
acb bac bca cab cba## sample
abc
acb
bac
bca
cab
cba
</p>