Palindromic Substrings

medium1-D Dynamic Programmingexpand around center, count palindromesB75Solve on LeetCode#647

Part of Practice: Strings & Coins

Given a string s, count how many of its substrings are palindromes — strings that read the same forwards and backwards. Substrings at different positions count separately even when their text is identical: "aa" contains the substring "a" twice, and each occurrence counts.

Constraints: 1 <= s.length <= 1000, lowercase letters only.

Examples

Input:
s = "abc"
Output:
3

Only the single characters qualify: "a", "b", "c".

Input:
s = "aaa"
Output:
6

Three single "a"s, two "aa"s (positions 0-1 and 1-2), and one "aaa".

Hints

One at a time — struggle first, peek second.

Your thinking space — verify on LeetCode, then mark it.