Palindromic Substrings

IF
AlgoAxiomStaff Engineers
JSTS
Medium20 mins

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

A substring is a contiguous sequence of characters within the string. A string is palindromic if it reads the same backward as forward.

Examples

Example 1:

Input: s = "abc"

Output: 3

Explanation: The three palindromic substrings are: "a", "b", "c".

Example 2:

Input: s = "aaa"

Output: 6

Explanation: The six palindromic substrings are: "a", "a", "a", "aa", "aa", "aaa".

Constraints

  • 1 <= s.length <= 1000
  • s consists of only lowercase English letters.
Source: Dynamic Programming pattern — AlgoAxiom
JavaScript
Test Case 1
root = [1, 2, 3]
Test Case 2
root = [1, 2, 3, 4, 5]
Idle