JOIN
Get Time

   Problem Statement  

 Problem Statement for PalindromeFactory

Problem Statement

    A palindrome is a string that reads the same forward and backward. Not all strings are palindromes and we are going to fix that.

In this problem we consider four edit operations:

  1. Insert a character at any position of a string (including the beginning and the end)
  2. Delete a character at any position of a string
  3. Change a character at any position of a string
  4. Swap any two different characters (not necessarily adjacent)


You can apply the first three operations any number of times, but the last operation can be applied at most once.



You are given a String initial. Return the minimal number of operations needed to make a palindrome from it.
 

Definition

    
Class:PalindromeFactory
Method:getEditDistance
Parameters:String
Returns:int
Method signature:int getEditDistance(String initial)
(be sure your method is public)
    
 

Constraints

-initial will contain between 1 and 50 lowercase letters ('a'-'z'), inclusive.
 

Examples

0)
    
"abba"
Returns: 0
The string is already a palindrome.
1)
    
"dabba"
Returns: 1
We can delete the first letter to make a palindrome.
2)
    
"babacvabba"
Returns: 2
Delete 'v' and swap the first two characters.
3)
    
"abc"
Returns: 1
We can change 'c' to 'a' to get a palindrome in one operation.
4)
    
"acxcba"
Returns: 1
Insert 'b' after the first character.
5)
    
"abcacbd"
Returns: 1
Swap 'd' with 'a' in the middle.

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.

This problem was used for:
       Single Round Match 439 Round 1 - Division II, Level Three