PIXELBANKv8.3.0
Menu

Palindromic Substrings

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
Editor

Test Results

0/0
Run code to see test results.