Search⌘ K
AI Features

Palindromic Substrings

Explore how to count the number of palindromic substrings in a given string using dynamic programming. Understand the problem constraints and develop efficient algorithms to identify substrings that read the same forwards and backwards. This lesson helps you practice these concepts in a hands-on coding environment.

Statement

Given a string, s, return the number of palindromic substrings contained in it. A substring is a contiguous sequence of characters in a string. A palindrome is a phrase, word, or sequence that reads the same forward and backward.

Constraints:

  • 11 \leq s.length 1000\leq 1000

  • s consists of only lowercase English characters.

Examples

Understand the problem

Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:

Technical Quiz
1.

What is the number of palindromic substrings in the string “car”?

A.

1

B.

2

C.

3

D.

4


1 / 3

Figure it out!

We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.

Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence.

1
2
3
4
5

Try it yourself

Implement your solution in the following coding playground.

JavaScript
usercode > main.js
function countPalindromicSubstrings(s) {
// Replace this placeholder return statement with your code
return -1;
}
export { countPalindromicSubstrings };
Palindromic Substrings