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.
Complete the function findLexicographicallySmallestString in the editor.
findLexicographicallySmallestString has the following parameter:
String s: the original string
Returns
String: the lexicographically smallest string that meets the condition or "-1" if no such string exists
Examples
01 · Example 1
s = "abbcd" return = "abcab"
🍊
More Amazon problems
- Get the Fewest Moves (~Operations~)~Seen Jun 2026
- Create Array Generator ServiceSeen Jun 2026
- Minimum Merge ConflictsOA · Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Drone Delivery RouteOA · Seen Jun 2026
- Minimum Operations to Make Array ValidOA · Seen Jun 2026
- Sort Bug Report FrequenciesOA · Seen Jun 2026
- Maximum Equal Parts for PrefixesOA · Seen Jun 2026
public String findLexicographicallySmallestString(String s) {
// write your code here
}
s"abbcd"
expected"abcab"
sign in to submit