Alogirthm to find the longest palindrome in a string in O(n^2)