Problem · String

Find Lexicographically Smallest String

Learn this problem
HardAmazon logoAmazonFULLTIMEOA
See Amazon hiring insights

Problem statement

Given a character string, find the lexicographically smallest string of the same length that is greater than the original string, with the condition that no two adjacent characters are the same. If no such string exists, return -1.

The string only contains letters, with 'a' being the smallest and 'z' being the largest.

Function

findLexicographicallySmallestString(s: String) → String

Complete the function findLexicographicallySmallestString in the editor.

findLexicographicallySmallestString has the following parameter:

  1. String s: the original string

Returns

String: the lexicographically smallest string that meets the condition or "-1" if no such string exists

Examples

Example 1

s = "abbcd"return = "abcab"
🍊

More Amazon problems

drafts saved locally
public String findLexicographicallySmallestString(String s) {
  // write your code here
}
s"abbcd"
expected"abcab"
checking account