TopCoder problem "ThePalindrome" used in SRM 428 (Division II Level One)



Problem Statement

    John and Brus are studying string theory at the university. Brus likes palindromes very much. A palindrome is a word that reads the same forward and backward. John would like to surprise Brus by taking a String s, and appending 0 or more characters to the end of s to obtain a palindrome. He wants that palindrome to be as short as possible. Return the shortest possible length of a palindrome that John can generate.
 

Definition

    
Class:ThePalindrome
Method:find
Parameters:String
Returns:int
Method signature:int find(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)
    
"abab"
Returns: 5
"ababa" is the shortest palindrome that John can get.
1)
    
"abacaba"
Returns: 7
Already a palindrome.
2)
    
"qwerty"
Returns: 11
All characters are different.
3)
    
"abdfhdyrbdbsdfghjkllkjhgfds"
Returns: 38

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13519&pm=10182

Writer:

Vasyl[alphacom]

Testers:

PabloGilberto , Olexiy , ivan_metelsky

Problem categories:

Dynamic Programming