cswork / OAOpen practice workspace

AmazonOA #251

Lexicographically Smallest Palindrome Possible

Estimated MediumStatement and editorial — judging is being prepared

Topics (AI-labelled)HashingStringsGreedy

Giv

Constraints

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

Example 1

Input:

s = "a?rt???"

Output:

"aartraa"

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

Example 2

Input:

s = "bx??tm"

Output:

"-1"

Explanation: No character can be added to make it a palindrome.

Example 3

Input:

s = "ai?a??u"

Output:

"aaiuiaa"

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

Editorial

Loading solution…