Palindromic Substrings

Med
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start•← → to step•? all shortcuts

Solution Guide: Palindromic Substrings

Approach

Treat each index (and gap between indices) as a palindrome center, then expand while characters match.

Complexity Analysis

Time
O(n^2)
Space
O(1)

Pattern

Expand Around Center

Why It Works

Every palindrome has a unique center, so enumerating all centers counts all palindromic substrings exactly once.

Updated Mar 2026