MEDIUMasked at 4 companies

Longest Palindromic Subsequence

A medium-tier problem at 64% community acceptance, tagged with String, Dynamic Programming. Reported in interviews at LinkedIn and 3 others.

Founder's read

Longest Palindromic Subsequence is a medium DP problem that shows up in LinkedIn, Nutanix, Cisco, and TCS interviews. The acceptance rate sits at 64%, which sounds high until you realize most people jam a greedy or brute-force approach and watch it fail. The trick isn't obvious: you need to see that finding the longest palindrome is equivalent to finding the longest common subsequence of the string and its reverse. That insight separates people who grind DP patterns from people who code-golf their way through.

Companies asking
4
Difficulty
MEDIUM
Acceptance
64%

Companies that ask "Longest Palindromic Subsequence"

If this hits your live OA

Longest Palindromic Subsequence 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 used it to pass JPMorgan's OA and system design loop.

Get StealthCoder
What this means

The naive instinct is to expand around centers or use a greedy scan. Both fail on non-obvious palindromes. The real solution is DP: build a table where dp[i][j] represents the longest palindromic subsequence between indices i and j. If s[i] equals s[j], extend the inner result by 2. If not, take the max of excluding left or right. The complexity is O(n^2) time and space, manageable for most assessments. Common failure point: candidates mess up the recurrence relation or forget to initialize base cases. If this pattern hits your live OA and you blank on the DP formulation, StealthCoder surfaces a clean solution in seconds, invisible to the proctor.

Pattern tags

The honest play

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

Longest Palindromic Subsequence recycles across companies for a reason. It's medium-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 used it to pass JPMorgan's OA and system design loop. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Longest Palindromic Subsequence interview FAQ

Is Longest Palindromic Subsequence still asked at FAANG?+

It appears in reports from LinkedIn, Cisco, Nutanix, and TCS regularly. It's not as common as substring problems, but it's frequent enough to warrant preparation if you're targeting those companies. The 64% acceptance rate reflects that it's medium-difficulty with a clear DP path once you see it.

What's the key insight I'm missing if I can't solve it?+

You likely think it's about string traversal or greedy selection. The insight is recognizing that longest palindromic subsequence equals the LCS of the string and its reverse. Once you have that, it's a standard two-pointer DP. That connection is rarely obvious without exposure.

How does this relate to other palindrome problems?+

Longest Palindromic Substring is about contiguous characters. This problem allows gaps (subsequence). Both are DP, but substring uses center-expansion and is O(n^2) in worst case. Subsequence always requires DP table and is harder to optimize. Knowing the difference saves you from coding the wrong approach.

What's the space complexity trade-off?+

Standard DP solution is O(n^2) space and time. You can optimize space slightly by using only two rows if you process bottom-up, but it's rarely worth it in an interview. Most assessments time out before space becomes the limiter. Stick with the clean O(n^2) DP table.

Will I see edge cases that break my solution?+

Single character returns 1. Empty string returns 0. Entire string is palindrome returns n. The DP table handles these naturally if initialized correctly. The trap is off-by-one errors in loop bounds or confused recurrence. Test on 'a', 'ab', 'aba', and you'll catch most bugs.

Want the actual problem statement? View "Longest Palindromic Subsequence" 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.