Palindromic Substrings
Medium · Strings · String · Dynamic Programming · Two Pointers
Problem
Count how many substrings of s are palindromes. Substrings at different positions count separately even if they are identical.
Examples
Input: s = "abc" Output: 3
The three single characters.
Input: s = "aaa" Output: 6
"a" three times, "aa" twice, and "aaa".
Constraints
- 1 <= len(s) <= 1000
- Lowercase English letters
Approaches
- Dynamic programming table — time O(n²), space O(n²)
Related problems
Start free on Cariara · Coding problems · System design studio