v9.1.1
Menu

Palindromic Substrings

mediumFREEDynamic ProgrammingBlind 75

Given a string s, return the number of palindromic substrings in it. A single character is a palindrome.

Example

Input
aaa
Output
6
Reasoning
  • The string aaa has 3 characters, so there are 3 single-character palindromic substrings: a, a, a.
  • There are also 2 two-character palindromic substrings: aa, aa.
  • Additionally, there is 1 three-character palindromic substring: aaa.
  • To find the total number of palindromic substrings, we sum these up: 3+2+1=63 + 2 + 1 = 6.

Constraints

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

More from Blind 75

solution.py

Test results

Sign in to run your code against the test cases.