Longest Palindromic Substring
Medium · Strings · String · Dynamic Programming · Two Pointers
Problem
Return the longest substring of s that reads the same forwards and backwards. If several tie, any one of them is accepted.
Examples
Input: s = "babad" Output: "bab"
"aba" is equally valid.
Input: s = "cbbd" Output: "bb"
An even-length palindrome.
Constraints
- 1 <= len(s) <= 1000
- s contains letters and digits
Approaches
- Dynamic programming table — time O(n²), space O(n²)
Related problems
Start free on Cariara · Coding problems · System design studio