InferenceAI

Enter at least two characters to search.

Start free

Count Palindromic Substrings

mediumDynamic Programming25 min25 XP

Return the number of palindromic substrings of s. Substrings at different positions count separately, even if they are equal.

Examples

EXAMPLE WALKTHROUGHsingle letters only

A guided view of the published example, not a trace of your code.

INPUT["abc"]
TASKpalindromic_substring_count()
EXPECTED OUTPUT3

Start with the input values shown in this example.

Example 1 of 3

Input: s = "abc"

Output: 3

Explanation: single letters only

Input: s = "aaa"

Output: 6

Explanation: all equal

Input: s = ""

Output: 0

Explanation: empty

Hint 1

Expand around each of the 2n - 1 centres and count every successful expansion.

Topics

DSADynamic ProgrammingPython