Compute Encoded Product Name
Amazon's software team utilizes several algorithms to maintain data integrity, one of which targets the encoding of symmetrical names. Symmetrical names are unique in that they read identically in both directions, similar to palindromes in language parlance.
The chief aim of the algorithm is to rearrange the characters in the original symmetrical name according to these criteria:
Given an initial symmetrical name that contains only lowercase English characters, compute the encoded name.
A string is considered to be lexicographically smaller than the string t of the same length if the first character in s that differs from that in t is smaller. For example, "abcd" is lexicographically smaller than "abdc" but larger than "abaa".
Note that the output encoded name could match the original name if it's already the smallest lexicographically.
Complete the function computeEncodedProductName in the editor.
computeEncodedProductName has the following parameter:
string nameString: the initial symmetrical string name.
Returns
string: the encoded nameString
1Example 1
Rearrange the original nameString to generate "xyyx",
which is a palindrome and also the smallest possible.
2Example 2
The original nameString "ded" is already the smallest lexicographical palindrome possible, so it remains unchanged.
Constraints
Limits and guarantees your solution can rely on.
- 1 ≤ |nameString| ≤ 105
nameStringconsists of lowercase English letters only.nameStringis a palindrome.