Palindromic Substrings

Given a string s, return the number of palindromic substrings present in s.

A palindrome is a string that reads the same forward and backward.

A substring is a contiguous sequence of characters within a string.

Substrings with the same characters but occurring at different positions are counted separately.

Example 1:

Input: s = "aba"

Output: 4

Explanation: The palindromic substrings are:

"a", "b", "a", "aba"

Example 2:

Input: s = "aab"

Output: 4

Explanation: The palindromic substrings are:

"a", "a", "b", "aa"

Now Your Turn!

Pick the correct output for the given input

Input: s = "xyz"

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= s.length <= 1000
  • s consists only of lowercase English letters.
0
class Solution {
public:
int countSubstrings(string s) {
// Your code goes here
return 0;
}
};
Test Case

Input:

S