Longest Palindromic Substring
A palindrome reads the same from left to right and right to left. A practical approach for the longest palindromic substring is expand-around-center: every palindrome has a center, which can be a character for odd-length palindromes or a gap between characters for even-length palindromes.
Expand-around-center takes O(n²) time in the worst case.
Auxiliary space is O(1), excluding the returned substring.
Dynamic programming can also solve the problem in O(n²) time and O(n²) space.
Manacher's Algorithm solves the problem in O(n) time but is more complex.
For production code, I would choose the approach based on input size and maintainability requirements.
0-2 years experience
2-5 years experience
5-8 years experience
8+ years experience