Longest palindromic substring

Write codeMedium30 minAmazon and Microsoft style

Your task

Return the longest contiguous palindromic substring of s. If several have the maximum length, return the one that starts at the earliest index. For the empty string return the empty string. For example "babad" returns "bab" (the earliest-starting of the two length-3 answers). Strings can be up to ~1000 characters; an O(n^2) expand-around-center solution is acceptable.

Examples

longest_palindrome(s: str) -> str
Example 1
Inputlongest_palindrome("babad")
Output"bab"