What are the main approaches to finding the longest palindromic substring, and how do they compare?
There are three main approaches. The first expands around every possible centre, treating both odd-length and even-length palindromes, and is quadratic in the worst case. The second uses dynamic programming, building up a table of which substrings are palindromes, and is also quadratic in space. The third is Manacher's algorithm, which reuses information about palindromes already found to keep the total work linear.
The expanding approach is the one to reach for in an interview. Its structure is simple: a palindrome has a centre, which is either a single character for odd lengths or a gap between two characters for even lengths. For each of the n characters and n minus one gaps, expand outwards while the mirrored characters match, and track the longest run found. The total cost is quadratic only when the input is one long palindrome, because each centre then expands all the way to the ends.
The dynamic programming version asks the question differently: is the substring from i to j a palindrome if the characters match and the inner substring from i plus one to j minus one is a palindrome? That recurrence is clean but it fills an n by n table, which is quadratic in memory and usually the wrong trade for a string problem.
The trade-off to name is that Manacher's algorithm is linear but genuinely hard to derive in an interview, and the interviewer cannot expect you to invent it. The honest framing is: I would implement the expanding approach for a single query, and if the string is processed many times or the input is enormous, I would look for a structure that supports repeated queries, such as a palindromic tree, rather than claiming Manacher is obvious.