How can I find the lexicographicaly smallest string that doesn't start with a given prefix AND is lexicographicaly bigger than the given prefix? Example:
prefix : cat; next string : cau
prefix : cazz next string; cb
Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It only takes a minute to sign up.Sign up to join this community
There is no solution if all characters in the input string are equal to the last character in the alphabet (this includes the case of the empty string).
Otherwise, as long as the last character in the input string is the last character in the alphabet, remove it from the string. Then replace the last character of the result with the next character in the alphabet.