Blind 75
53 / 75Free practice

Palindromic Substrings

Medium · Dynamic programming

Jump to code

Count all nonempty contiguous palindromic substrings. Substrings at different positions count separately even when their text is identical.

Examples

Example 1

s = "abc"

Output: 3

Example 2

s = "aaa"

Output: 6

Constraints

  • 1 <= s.length <= 1000
  • s consists of lowercase English letters.
Need a hint?

Every successful center expansion discovers one palindrome.

Asked in real interviews

Candidates reported versions of Palindromic Substrings from these company interviews. Some company questions are locked and open with Premium or XP.

Browse all real coding interview questions

Accepted submissions mark this problem complete. Progress stays in this browser.

Run checks 5 examples. Submit checks all 7 cases. A free account runs this problem; no XP needed.
Language
Case 1
Input
[
  "abc"
]
Expected
3
Case 2
Input
[
  "aaa"
]
Expected
6
Case 3
Input
[
  "a"
]
Expected
1
Case 4
Input
[
  "ab"
]
Expected
2
Case 5
Input
[
  "abba"
]
Expected
6

Drafts are saved per language in this browser when storage is available.