Question: 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
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 as 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 backwards as forwards.
Example
Suppose dna "abca", substrings of dna with their costs are
abcd with cost
ab cost we can change b to a and it becomes aa which is a palindrome.
"abc cost we can change b to c and it can be rearranged to "cac" which is a palindrome.
abca cost we can change b to c and it becomes "acca" which IS a palindrome.
bc cost we can change b to c and it becomes cc which is a palindrome.
"bca", cost we can change c to a and it can be rearranged to "aba" which is a palindrome.
ca cost we can change c to a and it becomes aa which is a palindrome.
Hence the answer is
Function Description
Complete the function getTotalPalindromeTransformationCost in the editor below. The function
returns me total sum of palindrome transformation costs across all substrings,
getTotalPalindromeTransformationCost has the following parameter:
dna: A string
Constraints : dnae
Sample Input For Custom Testing
acbaed
Sample Output
Explanation
Given dna "acbaed",
acbade have cost
All substrings of length ie accbbaaeed have cost we can change either of the character to other.
acbcba "bae". "aed" have cost we can change last character to first character in each of them.
acba has cost we can change b to a
"acbae has cost we can change c to e and it can be rearranged to "aebea" which is a palindrome.
"acbaed" has cost we can change c to e and b to d then it cn be rearranged to "aeddea" which is a palindrome. Similarly, "cbae "baed" and "cbaed" have cost
Hence the answer is
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
