One approach would be to consider each character in the string as possible "center" of the palindrome, then expand left and right as long as the character at the left position is equal to the character on the right position (which is a requirement for the sub-string to be a palindrome, obviously have to consider the two sub-cases of sub-string being of odd and even length). Doing this for all positions 1..n in the source string will give you the longest palindrome from consecutive characters contained in the string.