HARDasked at 1 company

Count Different Palindromic Subsequences

A hard-tier problem at 46% community acceptance, tagged with String, Dynamic Programming. Reported in interviews at Uber and 0 others.

Founder's read

Count Different Palindromic Subsequences is a hard DP problem that Uber asks. You're given a string and need to count distinct palindromic subsequences, not substrings. The trap is that naive DP blows up the state space, and you'll waste 20 minutes building the wrong recurrence. Most candidates either double-count or miss the optimization that uses character positions to prune redundant states. If this hits your live assessment and you blank on the state compression trick, StealthCoder surfaces a working solution in seconds, invisible to the proctor.

Companies asking
1
Difficulty
HARD
Acceptance
46%

Companies that ask "Count Different Palindromic Subsequences"

If this hits your live OA

Count Different 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. Made for the engineer who has done the work but might still blank with a webcam pointed at him.

Get StealthCoder
What this means

The core insight is that a palindromic subsequence is defined by its character bounds and what's between them, so you can't just count by length or occurrence. The trick is DP with memoization where the state is the substring indices, and you track whether adding a new character at the boundary creates a new palindrome or repeats an old one. Most people try to recurse on every character and end up with O(n^3) or worse without pruning. The key optimization watches for matching character pairs at string boundaries: when you find s[left] == s[right], you need to count carefully to avoid duplicates from inner recursions. Without this compression, you'll TLE or produce wrong counts. This is exactly the kind of problem where the contest timer kills you, but StealthCoder bridges the gap on OA day.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Count Different 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. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Different Palindromic Subsequences interview FAQ

How hard is this really compared to other DP strings?+

It's harder than standard substring DP because you're tracking subsequences, not contiguous ranges, and avoiding duplicate counts across different recurrence paths. The 46% acceptance rate reflects that most candidates get lost in state design or miss the boundary optimization entirely.

Is Uber still asking this one?+

Uber is in the input data, so yes, it appears on their list. Hard DP strings are stable interview problems at scale, especially for backend and platform roles where string optimization matters.

What's the exact trick I'm missing?+

When s[left] == s[right], you can't just recurse inward. You need to check if there are matching characters inside the range. If yes, you're reusing sub-palindromes and must subtract duplicates. If no, you add new ones from the boundary. This detail separates AC from WA.

Do I need to code this by hand without a reference?+

In a timed OA, yes. But the DP skeleton is small once you lock the state. The hard part is proving your count logic is sound, which is where candidates usually crack under time pressure.

How does this relate to Longest Palindromic Subsequence?+

LPS finds length; this counts distinct palindromes. They share DP structure but this problem adds a counting layer and boundary compression rules. If you've done LPS, you have half the mental model; the other half is deduplication logic.

Want the actual problem statement? View "Count Different Palindromic Subsequences" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.