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
- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
- Product Category Group SizesPHONE SCREEN · Seen May 2026
- Count Connected ComponentsPHONE SCREEN · Seen May 2026
public String findLexicographicallySmallestString(String s) {
// write your code here
}
s"abbcd"
expected"abcab"
sign in to submit