Given a string, find the lexicographically smallest palindrome if possible

For Example:
Input : malayalam
Step 1:
frequencies of characters:
m = 2, a = 4, l = 2, y = 1
sort the characters:
['m', 'l', 'a']
Step 2:
1 --> palindrome = 'y'
2 --> palindrome = 'mym'
3 --> palindrome = 'lmyml'
4 --> palindrome = 'almymla'
5 --> palindrome = 'aalmymlaa'
Output: aalmymlaa

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store