Reviewed by Aditya Kumar · Last reviewed 2026-03-24
**Expand Around Center:** For each center (char or between chars), expand while palindromic. O(n²) time, O(1) space. Manacher's = O(n) but complex. def longest_palindrome(s): def expand(l, r): while l >= 0 and r < len(s) and s[l] == s[r]: l -= 1; r += 1...
Expand Around Center: For each center (char or between chars), expand while palindromic. O(n²) time, O(1) space. Manacher's = O(n) but complex.
def longest_palindrome(s):
def expand(l, r):
while l >= 0 and r < len(s) and s[l] == s[r]: l -= 1; r += 1
return s[l+1:r]
return max((expand(i,i) or expand(i,i+1) for i in range(len(s))), key=len, default='')
Red Flag: O(n³) check every substring. Pro-Move: 'Expand-around-center—we use for log message anomaly detection (palindrome = possible replay).'
According to DataEngPrep.tech, this is one of the most frequently asked Python/Coding interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.