What is the minimum number of characters than need to be inserted to to the string
Brilliantforever
to make it a palindrome?
As an explicit example:
-"ba" becomes a palindrome by adding 1 character as bab
-"lov" becomes a palindrome by adding 2 characters as lovol
Details and Assumptions
Characters can be inserted at any postion
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Besides a possible lone letter in the middle, the palindrome will contain two of every letter, as there is only one B , A , N , T , F , O , and V , we will have to add at least 6 letters, 7 if none of them are directly in the middle of the palindrome.
Observing what is left if we take these lone letters out we find R I L L I R E E R , and we want the maximum amount of symmetry which could happen from the middle of the E 's or the middle of the L 's. As there are more pairs of letters surrounding the L 's these are most symmetric and it makes most sense to make the string palindromic about the middle of them.
Looking back at the original string, these letters are already together thus there will be an even number of each letter, we must add one of all the letters that are alone 7 , as there are 3 R s originally we must add 1 , and 2 e 's as there are 2 initially on the right side of the palindromic divide. For a total of 7 + 1 + 2 = 1 0 that must be added