FastPrepFastPrep
Problem Brief

Find Lexicographically Smallest String

FULLTIMEOA
See Amazon online assessment and hiring insights

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 Description

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

1Example 1

Input
s = "abbcd"
Output
"abcab"
Explanation
🍊
public String findLexicographicallySmallestString(String s) {
  // write your code here
}
Input

s

"abbcd"

Output

"abcab"

Sign in to submit your solution.