Count Palindromic Subsequences
A hard-tier problem at 39% community acceptance, tagged with String, Dynamic Programming. Reported in interviews at Citadel and 3 others.
Count Palindromic Subsequences is a hard string problem that shows up in assessments at Citadel, Salesforce, Goldman Sachs, and Uber. With a 39% acceptance rate, it's the kind of problem that separates candidates who can spot patterns from those who burn time on brute force. You need to count all distinct palindromic subsequences of length greater than 1 in a given string. The trap is thinking you can enumerate every subsequence and check if it's a palindrome. That explodes exponentially. The actual solution uses dynamic programming with a focus on tracking character boundaries and avoiding double-counting. If this problem hits your live OA and you blank on the DP state design, StealthCoder surfaces a working approach in seconds, invisible to the proctor.
Companies that ask "Count Palindromic Subsequences"
Count Palindromic Subsequences is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.
Get StealthCoderThe core trick is realizing that palindromic subsequences are defined by their first and last characters. A palindrome starting and ending with character 'a' at positions i and j (where i < j) can wrap other palindromes in the middle. The DP state is dp[i][j] = count of distinct palindromic subsequences in substring s[i:j+1]. When s[i] equals s[j], you can form new palindromes by wrapping both characters around existing palindromes from the inner range, plus the single-character pair itself. The hard part is avoiding duplicates when the same character appears multiple times in the string. Most candidates try memoizing all subsequences directly and hit time limits. Others confuse this with standard palindrome problems like longest palindromic subsequence. The solution requires careful handling of left and right pointers to skip duplicate characters and merge results correctly. StealthCoder is the safety net if you can't reconstruct the exact DP recurrence under pressure.
Pattern tags
You know the problem.
Make sure you actually pass it.
Count Palindromic Subsequences recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Count Palindromic Subsequences interview FAQ
Is this as hard as it looks, or is there a simpler pattern I'm missing?+
It's genuinely hard. The 39% acceptance rate reflects that. The trap is the deduplication logic when characters repeat. You can't just count and move on; you need to track which palindromes you've already seen. Most candidates get a partial DP working but TLE or produce wrong counts because they didn't handle the left/right pointer skip correctly.
Do Citadel and Goldman Sachs really ask this in their OAs?+
Yes, it's in their reported problem lists. Both firms test hard DP problems. They're evaluating whether you can design a non-obvious state, avoid exponential blowup, and reason about deduplication under time pressure. This is a filter problem.
What's the most common wrong approach?+
Generating all subsequences, checking each for palindromes, and using a set to deduplicate. Works on small inputs; dies on anything above length 20. The DP approach runs in O(n^3) or O(n^2) depending on implementation. There's no brute force shortcut here.
How does this relate to longest palindromic subsequence?+
They're different problems. LPS finds the longest palindrome in a string; this counts distinct palindromes of any length over 1. LPS can be solved with simpler DP (reverse string, find LCS). Counting distinct palindromes requires tracking boundaries and avoiding duplicates, which is the harder part.
If I see this on test day and don't recognize it, what's my move?+
Start with the brute force to get partial credit, then optimize if time allows. But recognize the exponential wall quickly. Then pivot to thinking DP: what's the state? What breaks when the same character repeats? That line of thinking leads to the correct approach faster than coding blind.
Want the actual problem statement? View "Count Palindromic Subsequences" on LeetCode →