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! 🌷
dna = "abca" return = 6
dna = "wwwww" return = 0
dna = "wwwww", all substrings are already palindromes with cost = 0, hence the total sum is 0.dna = "acbaed" return = 19
1 <= |dna| <= 2 * 10^5The string dna contains lowercase english letters only- Periodic Table Word FormationsPHONE SCREEN · Seen Jun 2026
- Fountain SafetyONSITE INTERVIEW · Seen Jun 2026
- Consolidate On-Call RotationsOA · Seen Jun 2026
- Detonate Bombs with Chain ReactionsONSITE INTERVIEW · Seen May 2026
- Evaluate a Nested Math ExpressionONSITE INTERVIEW · Seen May 2026
- Tic-Tac-Toe Game StatusPHONE SCREEN · Seen May 2026
- Longest Dictionary TokenizationPHONE SCREEN · Seen May 2026
- Minimum Cars for Rental RequestsONSITE INTERVIEW · Seen Apr 2026
public int setTotalPalindromeTransformationCost(String dna) {
// write your code here
}