Count Distinct Palindromic Substrings

Given a string STR, your task is to determine the total number of palindromic substrings present in the string.

Input:

The first line contains an integer 't', representing the number of test cases. Each subsequent line contains the string STR for which the count of palindromic substrings needs to be identified.

Output:

Output the total count of palindromic substrings for each test case on a separate line.

Example:

Input:
 1
"abbc"
Output:
 5 
Explanation:

The palindromic substrings for the input "abbc" are ["a", "b", "b", "c", "bb"]. Therefore, the output is 5.

Constraints:

  • 1 <= t <= 100
  • 0 <= N <= 1000

Note:

A 'Palindrome' is a string that reads the same forward and backward, e.g., "abba". A 'Substring' is any contiguous sequence of characters from a string, e.g., in "abc", "a", "b", "c", "ab", "bc", and "abc" are all possible substrings.
Just implement the required function; printing will be handled internally.
AnswerBot
4mo

Count the total number of palindromic substrings in a given string.

  • Iterate through each character in the string and expand around it to find palindromic substrings.

  • Keep track of the count of palindrom...read more

Help your peers!
Select
Add answer anonymously...

Amazon Software Developer Intern interview questions & answers

A Software Developer Intern was asked 4mo agoQ. Given a linked list, find the n'th node from the end of the list.
A Software Developer Intern was asked 4mo agoQ. Given a tree, find its diameter (the longest path between two nodes in the tree)...read more
A Software Developer Intern was asked 4mo agoQ. Given a matrix, find the shortest distance between two given points located anyw...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked 4mo agoQ1. Given a linked list, find the n'th node from the end of the list.
A Software Developer Intern was asked 4mo agoQ2. Given a tree, find its diameter (the longest path between two nodes in the tree)...read more
A Software Developer Intern was asked 4mo agoQ3. Given a matrix, find the shortest distance between two given points located anyw...read more
Amazon Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits