01Palindromes grow from a centre
Every palindrome of odd length has a centre character. Define d1[i] as the radius of the longest odd palindrome centred at i: it covers s[i − d1[i] + 1 .. i + d1[i] − 1] and has length 2·d1[i] − 1.
For abacaba, d1 = [1, 2, 1, 4, 1, 2, 1]. The centre c has radius 4: the whole string.
The simple method expands around every centre while the two outer characters are equal. That is easy and often fine, but on aaaa…a every centre expands far, giving O(n²). Note also that a palindrome of radius r contains palindromes of radius r − 1, r − 2, … around the same centre, so d1[i] also counts the palindromes centred at i.