Design Gurus Logo
Palindromic Substrings (Medium)
Go Back

Problem Statement

Given a string, determine the number of palindromic substrings present in it.

A palindromic substring is a sequence of characters that reads the same forwards and backward. The substring can be of any length, including 1.

Example

    • Input: "racecar"
    • Expected Output: 10
    • Justification: The palindromic substrings are "r", "a", "c", "e", "c", "a", "r", "cec", "aceca", "racecar".
    • Input: "noon"
    • Expected Output 6
    • Justification: The palindromic substrings are "n", "o", "o", "n", "oo", "noon".
    • Input: "apple"
    • Expected Output: 6
    • Justification: The palindromic substrings are "a", "p", "p", "l", "e", "pp".

Constraints:

  • 1 <= s.length <= 1000
  • s consists of lowercase English letters.

Try it yourself

Try solving this question here:

Python3
Python3