Coding · should-tier · asked at Amazon, Apple, Google, Meta, Microsoft, Netflix
Palindromic Substrings
Problem
Given a string s, count how many of its substrings are palindromes. Substrings at different positions count separately even if their text is identical.
- The string is up to 1,200 characters.
sconsists of lowercase English letters.
Examples
s = "xyz"→3. Only the three single characters.s = "ooo"→6."o"three times,"oo"twice,"ooo"once.s = "xyyx"→6. Four singles plus"yy"and"xyyx".
Hints
- Instead of testing every substring, think about where a palindrome's middle is.
- If
s[lo..hi]is a palindrome ands[lo-1] == s[hi+1], you have found another one. If they differ, can any wider substring around this centre be a palindrome? - Expand around all
2n-1centres and count every successful expansion step; or filldp[i][j] = s[i]==s[j] and dp[i+1][j-1]and count the true cells.
Last reviewed 8 September 2026
Locked
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Secure payment by Stripe · instant access · refund questions: [email protected]
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.