Back to problems

Lexicographically Smallest Special String

Algorithm · Amazon · Hard

Given a string s, find the smallest string in lexicographic order that is strictly larger than s and is special. A string is special when no identical characters appear next to one another. Example The result is greater than the input, and each neighboring pair contains different characters. Changing the earliest possible character produces a larger string, and the remaining positions are filled with the smallest valid characters. Example Changing the third character…

Checking your access…