Count Palindrome Addition Choices
Problem statement
You are given a string inputStr. Choose either to add no letter or to add one lowercase English letter. Count the choices for which the resulting letters can be rearranged into a palindrome.
Adding the same letter at different positions counts as one choice. Different palindrome arrangements also count as the same choice. The answer is at most 27: one choice to add nothing and 26 choices of a letter.
Return the number of valid choices.
Function
countPalindromeAdditions(inputStr: String) → intExamples
Example 1
inputStr = "aabb"return = 27Both letter counts are even, so adding nothing works. Adding any one of the 26 letters leaves exactly one odd count, which also allows a palindrome. There are 1 + 26 = 27 choices.
Example 2
inputStr = "abbb"return = 2The counts of a and b are both odd. Adding either a or b leaves just one odd count. These choices can form abbba and bbabb, respectively. Adding nothing or another letter does not work.
Constraints
1 <= inputStr.length <= 100inputStrcontains only lowercase English letters.