Skip to content
BASA DSA

Palindromic Substrings

Medium1-D Dynamic Programming

Count all palindromic contiguous substrings, counting different index ranges separately even when their text is equal.

Example 1

Input
s = "aaa"
Output
6

Explanation

Three single letters, two aa ranges and one aaa range total six.

Example 2

Input
s = "abc"
Output
3

Explanation

Only the three single-character ranges are palindromes.

Example 3

Input
s = "abba"
Output
6

Explanation

Four single letters, bb and abba total six.

Constraints

  • 1 <= len(s) <= 1000
  • s contains lowercase English letters

Function contractcountSubstringsArguments: json
Loading draft…
SolutionRuns on your device
Loading draft…