Find the Longest Palindromic Substring
Company: eBay
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: Return the longest contiguous palindromic substring efficiently, choosing the earliest starting candidate when multiple maximum-length answers exist and handling empty input explicitly.
Constraints
- 0 <= len(s) <= 5000.
- s contains printable ASCII characters.
- For equal maximum lengths, return the palindrome with the earliest starting index.
Examples
Input: ('babad',)
Expected Output: 'bab'
Explanation: Both bab and aba have length three, so the earlier bab wins.
Input: ('cbbd',)
Expected Output: 'bb'
Explanation: The longest palindrome has even length.
Hints
- A palindrome is determined by a character center or a gap center.
- Use starting index as the secondary comparison key when lengths tie.