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.
Be the first one to answer
Add answer anonymously...
Amazon Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter