medium
strings
dynamic-programming
Given a string s, return the longest substring of s that is a palindrome.
A substring is a contiguous sequence of characters, and a palindrome reads the same forwards and backwards.
For example, the longest palindromic substring of "forgeeksskeegfor" is "geeksskeeg".
When more than one palindrome shares the maximum length, any of them is a valid answer. The test cases here are chosen so the longest palindromic substring is unique.
Examples
Example 1
Input: s = "racecar"
Output: "racecar"
Example 2
Input: s = "cbbd"
Output: "bb"
Example 3
Input: s = "forgeeksskeegfor"
Output: "geeksskeeg"
Example 4
Input: s = "abaxyzzyxf"
Output: "xyzzyx"
Running will execute all 4 cases.