1167. Count Palindromic Substrings (DP)

EasyDynamic ProgrammingSequence DP

Given a string s, count the number of palindromic substrings (contiguous), counting different positions separately even when the content is identical. The input is JSON {s}.

Input: JSON {s}.

Output: Integer — the number of palindromic substrings.

Examples

Example 1
Input: {"s":"abc"}
Output: 3
Explanation: Three single characters.
Example 2
Input: {"s":"aaa"}
Output: 6
Explanation: a, a, a, aa, aa, aaa.
Example 3
Input: {"s":"ab"}
Output: 2
Explanation: Two single characters.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →