Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Palindromic Substrings
MEDIUM
20 mins
74 upvotes
Strings
Dynamic Programming
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Strings
-
-
Dynamic Programming
-
-
Other topics
Problem solved
Badge
Skill meter
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Palindromic Substrings

Contributed by
Arindam Majumder
Medium
yellow-spark
0/80
Avg time to solve 20 mins
Success Rate 80 %
Share
74 upvotes

Problem Statement

You have been given a string STR. Your task is to find the total number of palindromic substrings of STR.

Example :
If the input string is "abbc", then all the possible palindromic substrings would be: ["a", "b", "b", c", "bb"] and hence, the output will be 5 since we have 5 substrings in total which form a palindrome.
Note :
A string is said to be a 'Palindrome' if it is read the same forwards and backwards. 
For example, “abba” is a palindrome, but “abbc” is not.

A 'Substring' is a contiguous sequence of characters within a string. 
For example, "a", "b", "c", "ab", "bc", "abc" are substrings of "abc".
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1 :
1
abc
Sample Output 1 :
3
Explanation For Sample Output 1:
All the substrings of the given string are "a", "b", "c", "ab", "bc", "abc".
The plaindromics substrings are "a", "b", "c". So the output will be 3.   
Sample Input 2 :
1
aaa
Sample Output 2 :
6
Reset Code
Full screen
Auto
copy-code
Console