Number of characters to create a palindrome

Question

A palindrome string reads the same backward as well as forward. Given a string, write a function to find the minimum number of characters that need to be inserted in order to convert the string to a palindrome.

Below are some examples:

  • aabaa: 0, it's already a palindrome
  • abcd: 3, dcb abcd
  • abcde: 4, edcb abcde

Solution

Access restricted

Subscribe to premium account to see the solution.

Get premium now