Problem
You get a string s. Return the number of substrings of s that are palindromes.
A substring is a part of a string with consecutive characters. A palindrome is a string that reads the same from left to right and from right to left.
Count each substring by its position. If two substrings have the same characters but start at different indexes, both substrings count.
Example 1
- Input:
- s = "aba"
- Output:
- 4
- Explanation:
- The palindromes are
"a","b","a"and"aba". The two"a"substrings start at different indexes, so both count.
Example 2
- Input:
- s = "kkk"
- Output:
- 6
- Explanation:
- The substring
"k"counts 3 times,"kk"counts 2 times and"kkk"counts 1 time.
Constraints
- 1 <= s.length <= 1000
- s has only lowercase English letters.
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Longest Palindromic Substring
Coding · Dynamic Programming · Manacher · String
- Push Dominoes
Coding · Dynamic Programming · String · Two Pointers
- Count Binary Substrings
Coding · String · Two Pointers
- Longest Palindromic Subsequence
Coding · Dynamic Programming · String
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 2 records
Meta
Leetcode 647. Palindromic Substrings
Reported Sep 1, 2026 · 4 source reports
JUNIOR, MID_LEVEL, SENIOR
Source snapshot: Nov 12, 2026
View sourceMicrosoft
Leetcode 647. Palindromic Substrings
Reported Jan 15, 2026 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 3 records
Goldman Sachs
Palindromic Substrings
Reported date not specified · Source window: 30d
Source snapshot: Oct 20, 2026
Source frequency score: 100. This is not an interview probability.
View sourceGoldman Sachs