Problem · String

Next Greater Perfect String

HardAmazonFULLTIMEOA
See Amazon hiring insights

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
drafts saved locally
public String nextGreaterPerfectString(String s) {
  // write your code here
}
s"abzzzcd"
expected"acababa"
sign in to submit