Count Palindromic Substrings Problem Statement

Given a string STR, determine the total number of palindromic substrings within STR.

Input:

The first line contains an integer 't' representing the number of test cases. For each test case, provide the string STR for counting palindromic substrings.

Output:

For each test case, return a single integer denoting the total count of palindromic substrings.

Example:

Input:
"t" = 1
STR = "abbc"
Output:
5
Explanation:

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

Constraints:

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

Here, t is the number of test cases, and N is the length of the string. Time Limit: 1 sec.

Note:

A 'Palindrome' reads the same forward and backward, such as "abba". A 'Substring' is a continuous sequence within a string, like "a", "b", and "abc" in "abc". Function implementation only required, output management is handled externally.
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.

  • Use dynamic programming to store pre...read more

Help your peers!
Select
Add answer anonymously...

Top Software Developer Interview Questions Asked at Cadence Design Systems

Q. Given an array, reverse the order of its elements in place.
Q. How would you find the sum of two numbers in a linear array (both sorted and uns...read more
Q. Pointers with increment/decrement, address of and value at operators (++,–,*,&)
Software Developer 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