Lexicographical order is often known as alphabetical order when dealing with strings.
It is similar to the order in which strings are arranged in a dictionary. A string is greater than another string if it comes later in a lexicographically sorted list.
Gaurav has a simple problem for which he needs your help.
Given a word, create a new word by swapping some or all of its characters. This new word must meet two criteria:
For example, given the word w=abcd, the next largest word is w=abdc.
Basically, Gaurav needs to find the smallest string which is lexographically greater than the given string using the same characters present in the input string.
Input Format:
Constraints:
string w will contain only letters in the range ascii[a..z].
Output Format:
For each test case, output the string meeting the criteria. If no answer exists, print no answer.
For abcd , the immediately next greater string is abdc
For adeg, the immediately next greater string is adge
For dcba, there is no string lexographically greater than it using the same characters, so "no answer".