A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g., 'madam' or 'racecar'. Even the letter 'x' is considered a palindrome.
You are given a string
s. Write a function that returns the longest contiguous palindromic substring in
s (it could be the entire string). In the event that there are multiple longest palindromic substrings, return the first to occur.
I'm not trying to trick you here:
You can assume that all inputs are valid strings.
Only the letters a-z will be used, all lowercase (your solution should, in theory, extend to more than just the letters a-z though).
NOTE: Quadratic asymptotic complexity (O(N^2)) or above will NOT work here.
(Note: "bab" occurs before "aba")
Want to propose a challenge idea for a future post? Email email@example.com with your suggestions!