Get Special String
Learn this problemProblem statement
Developers at Amazon are working on a text generation utility for one of their new products.
Currently, the utility generates only special strings. A string is special if there are no matching adjacent characters. Given a string s of length n, generate a special string of length n that is lexicographically greater than s. If multiple such special strings are possible, then return the lexicographically smallest string among them.
Notes:
A string a is lexicographically smaller than a string b if and only if one of the following conditions holds:
Important Considerations:
Function
getSpecialString(s: String) → String
Complete the function getSpecialString in the editor below.
getSpecialString has the following parameter:
s: the input string
Returns
string: the lexicographically smallest string that is greater than s. If no such special string exists, return "-1".
𓇼 ⋆。˚🐳 Credit to Agnes and spike!𓂃𓈒𓏸 𓆝
Examples
Example 1
s = "abbd"return = "abca"
Example 2
s = "abccde"return = "abcdab"Some valid special strings that are lexicographically greater than s = "abccde" include abcdab and abcdbc.
The lexicographically smallest special string greater than abccde is abcdab.
Example 3
s = "zzab"return = "-1"Constraints
s consists of lowercase English letters only.More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026