Lexicographical order is often known as alphabetical order when dealing with strings. A string is greater than another string if it comes later in a lexicographically sorted list.
Given a word, create a new word by swapping some or all of its characters. This new word must meet two criteria:
The next largest word is .
Complete the function biggerIsGreater below to create and return the new string meeting the criteria. If it is not possible, return
Complete the biggerIsGreater function in the editor below.
biggerIsGreater has the following parameter(s):
– string: the smallest lexicographically higher string possible or
The first line of input contains , the number of test cases.
Each of the next lines contains .
Sample Input 0
5 ab bb hefg dhck dkhc
Sample Output 0
ba no answer hegf dhkc hcdk
bais the only string which can be made by rearranging
ab. It is greater.
bband get a greater string.
hegfis the next string greater than
dhkcis the next string greater than
hcdkis the next string greater than
Sample Input 1
6 lmno dcba dcbb abdc abcd fedcbabcd
Sample Output 1
lmon no answer no answer acbd abdc fedcbabdc
YOU MIGHT ALSO LIKE
SUBSCRIBE TO OUR NEWSLETTER