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 a mirror in the middle of a word and checking if the letters on both sides match like reflections.
s = "b a n a n a"
indexes: 0 1 2 3 4 5
Check centers like:
a
b a n a n a
↑
Expand left and right to find palindrome