Mental Model
Find the longest part of a string that reads the same forwards and backwards by expanding around each center.
Analogy: Imagine looking for the biggest mirror reflection in a row of letters by checking from the middle outwards on both sides.
s = "b a b a d"
indexes: 0 1 2 3 4
Check centers at each index and between indexes:
b a b a d
ā
center at index 0
b a b a d
ā
center between index 0 and 1
b a b a d
ā
center at index 2
Each center tries to expand left and right to find palindrome.