FastPrepLexicographically Smallest Palindrome Possible 🍊

Lexicographically Smallest Palindrome Possible 🍊

Amazon logoAmazon● MediumOA
Learn

Problem statement

Given a String, return the lexicographically smallest palindrome possible or -1.

Function

getSmallestPalindrome(s: String) β†’ String

Examples

Example 1

s = "a?rt???"return = "aartraa"

Question marks can be replaced by a, r, a, a and we can make it palindrome.

Example 2

s = "bx??tm"return = "-1"

No character can be added to make it a palindrome.

Example 3

s = "ai?a??u"return = "aaiuiaa"

'?' is replaced by a, a and i and characters are rearranged to make it a palindrome.

Constraints

  • A mysterious untelling for now 🧐 As always, will add once find out

More Amazon problems

See Amazon hiring insights
public String getSmallestPalindrome(String s) {
  // write your code here
}
s"a?rt???"
expected"aartraa"
Checking account…