Facebook Pixel

Palindromic Substrings

Problem Statement

Given a string, count how many substrings are palindromes.

A substring is a contiguous sequence of characters (unlike subsequence, which can skip). A palindrome reads the same forwards and backwards.

s = "aaa"

Palindromic substrings:
- "a" at index 0
- "a" at index 1
- "a" at index 2
- "aa" (indices 0-1)
- "aa" (indices 1-2)
- "aaa" (indices 0-2)

Answer: 6
Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro