DNA Sequencing
Some data scientists are building a utility to analyze palindromic trends in the DNA sequencing of a string. The palindrome transformation cost of a string is defined as the minimum number of characters that need to be changed in it so that it can be rearranged to form a palindrome. For example, the palindrome transformation cost of the string "aabcd" is 1 since we can change the last character 'd' to 'c' so that the string becomes "aabcc" that can be rearranged to "acbca" which is a palindrome.
Given string dna, find the total sum of palindrome transformation cost of all the substrings of the given string.
Note: A palindrome is a sequence that reads the same backward as forward, for example, sequences "z", "aba" and "aaa" are palindromes, but sequences "xy", "rank" are not.
Complete the function setTotalPalindromeTransformationCost in the editor below. The function returns the total sum of palindrome transformation costs across all substrings.
setTotalPalindromeTransformationCost has the following parameter:
dna: string
🌷༊·° Now sending 1009th thank you to spike! 🌷
1Example 1
2Example 2
dna = "wwwww", all substrings are already palindromes with cost = 0, hence the total sum is 0.3Example 3
Constraints
Limits and guarantees your solution can rely on.
1 <= |dna| <= 2 * 10^5The string dna contains lowercase english letters only