TopCoder problem "Palindromize2" used in SRM 337 (Division II Level One)



Problem Statement

    

A palindrome is a string that reads the same from left to right as it does from right to left. Given a String s, return a palindrome that is produced by changing the minimum possible number of characters in s. Changing a character means replacing it with any single character at the same position. You are not allowed to remove or add any characters. If there are multiple answers, return the one that comes first alphabetically.

 

Definition

    
Class:Palindromize2
Method:minChanges
Parameters:String
Returns:String
Method signature:String minChanges(String s)
(be sure your method is public)
    
 

Constraints

-s will contain between 1 and 50 characters, inclusive.
-Each character of s will be a lowercase letter ('a'-'z').
 

Examples

0)
    
"ameba"
Returns: "abeba"
You can get "abeba" or "amema" with only 1 change. Among those two, "abeba" comes earlier alphabetically.
1)
    
"cigartragic"
Returns: "cigartragic"
The input is already a palindrome, so the best choice is to do 0 changes.
2)
    
"abcdef"
Returns: "abccba"
3)
    
"cxbpaxz"
Returns: "cxapaxc"

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7406

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10661&pm=7406

Writer:

soul-net

Testers:

PabloGilberto , brett1479 , Olexiy , Andrew_Lazarev

Problem categories:

Greedy, Search