Counts all palindromic substrings by expanding around each center; O(n²) time, O(1) space.
## What is it?
Count all palindromic substrings in a given string. Each character and each pair of consecutive identical characters can serve as a center from which you expand outward to find palindromes.
## How it works
**Expand Around Center:**
- For each index `i` (and each pair `i, i+1`), try to expand outward while `str[left] == str[right]`
- Count each valid expansion as one palindromic substring
- Total centers = `2n - 1` (n odd centers + n-1 even centers)
## When to use
- Counting or listing all palindromic substrings
- As a building block for "Longest Palindromic Substring" (return length instead of count)
- Problems involving substring palindromes
## Key Points
- O(n²) time — n centers, each expanded up to O(n) times
- O(1) space — no auxiliary structures needed
- Manacher's algorithm solves this in O(n) time, but expand-around-center is the standard interview approach