SDE II
Amazon is creating a system which always returns perfect strings. A perfect string is a string in which no 2 adjacent characters are same. You will be given a starting string which can be perfect or cannot be. You have to return the lexicographically next smallest perfect string greater than the current string lexicographically.
Examples
01 · Example 1
s = "abzzzcd" return = "acababa"
:)
02 · Example 2
s = "zzab" return = "-1"
Because there will be no perfect lexigraphically greater string than zzab.
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 nextGreaterPerfectString(String s) {
// write your code here
}
s"abzzzcd"
expected"acababa"
sign in to submit