Write longest_palindrome(s: str) -> str that returns a longest contiguous substring of s that reads the same forwards and backwards. If several have the maximum length, return any one of them.
Examples:
longest_palindrome("racecars")returns"racecar"longest_palindrome("abcd")may return"a","b","c"or"d"longest_palindrome("xabbay")returns"abba"(even length)
Constraints: 1 <= len(s) <= 3000, letters and digits.
⭐ Bonus: speed tests with strings up to 3,000 characters earn a star in O(n²). Checking every substring is O(n³).
Show hint
every palindrome grows outward from its middle, which is a character or the gap between two characters.