Medium

Quiz

#647 Palindromic Substrings

APPROACH

Given a string s, count and return the total number of substrings that are palindromes (they read the same forwards and backwards). Each character by itself is always a palindromic substring.

Example 1:

Input: s = "abc"
Output: 3
Explanation: Three palindromic strings: "a", "b", "c".

Example 2:

Input: s = "aaa"
Output: 6
Explanation: Six palindromic strings: "a", "a", "a", "aa", "aa", "aaa".
1 of 4
1:00

What is the optimal approach for this problem?