Problem · String
Set Total Palindrome Transformation Cost
Learn this problemProblem statement
A string is called "palindrome-like" if it can be rearranged in any way to become a palindrome.
For example, aabb is palindrome-like since it can be rearranged to abba.
For any string, you are allowed to change any number of characters to make it palindrome-like.
Let this minimum number of changes be the string's cost.
Given a string s, find the total sum of palindrome transformation costs of all substrings of s.
Also asked by Google: DNA Sequencing.
Function
setTotalPalindromeTransformationCost(s: String) → longExamples
Example 1
s = "abca"return = 6The substrings of "abca" with non-zero cost are "ab", "abc", "abca", "bc", "bca", and "ca". Each costs 1, while single-character substrings cost 0.
The total cost is therefore 6.
Constraints
1 <= n <= 10^5sconsists of lowercase English letters