I'll walk through the expand-around-center approach. For each index, you call a helper that expands outward from a given left and right pointer. You call it twice per index: once for odd-length and once for even-length palindromes.
function longestPalindrome(s):
start = 0
maxLen = 1
function expand(left, right):
while left >= 0 and right < s.length and s[left] == s[right]:
if right - left + 1 > maxLen:
start = left
maxLen = right - left + 1
left -= 1
right += 1
for i from 0 to s.length - 1:
expand(i, i)
expand(i, i + 1)
return s.substring(start, start + maxLen)