FastPrepLongest Palindromic Subsequence
Problems/Longest Palindromic Subsequence

Longest Palindromic Subsequence

AXQ Capital logoAXQ Capital● MediumFULLTIMEOA

Updated Dec 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported from an AXQ Capital online assessment for a full-time quantitative researcher role that the candidate had applied to online. The assessment had one coding task, named in the report as the well-known longest palindromic subsequence problem of medium difficulty: find the length of the longest subsequence of a string that is a palindrome. It also had a data task on predicting an income level from tabular data.

The report names the task without a statement, limits or examples. The statement and the limits (up to 1,000 lowercase letters) follow the usual version of this problem, and the examples are ours.

Our version is about 95% the same as the reported question.

Find the longest subsequence of the string s that is a palindrome, and return how many characters it has.

A subsequence is what remains after deleting zero or more characters from s; the remaining characters keep their original order but do not have to be next to each other. A palindrome is a string that is the same when it is reversed.

Function

longestPalindromeSubseq(s: String) → int

Examples

Example 1

s = "kabcbdk"return = 5

The letters k, b, c, b, k (positions 0, 2, 3, 4 and 6) form kbcbk, which reads the same both ways, so the answer is at least 5. It cannot be longer: in a palindrome every letter except possibly the middle one is matched by the same letter on the other side, so only one letter may be used an odd number of times. Here k and b appear twice each and a, c and d once each, so at most 2 + 2 + 1 = 5 letters can be used.

Example 2

s = "abab"return = 3

aba (positions 0, 1 and 2) is a palindrome of length 3. The only subsequence of length 4 is the whole string abab, which reads baba backwards, so it is not a palindrome. The answer is 3, even though each letter appears twice.

Example 3

s = "abcd"return = 1

No letter appears twice. A palindrome of length 2 or more needs its first and last letters to be equal, taken from two different positions, so none exists here. A single letter is a palindrome, so the answer is 1.

Constraints

  • 1 <= s.length <= 1000
  • s consists only of lowercase English letters.

More AXQ Capital Online Assessment questions

  • Perfect SubstringOA · Seen Nov 2026

Similar questions at other companies

  • Maximum Equal-Bit Pairs in a SubsequenceAmazon · OA
  • Longest Subsequence That Is a SubstringBooking.com · OA
  • Count Digit Replacements with No Equal Adjacent DigitsMicrosoft · OAMicrosoft interview questions
  • Palindrome CounterGoldman Sachs · OAGoldman Sachs interview questions
  • Longest String ChainVisa · OAVisa interview questions
  • Minimum-Cost Digit String DecodingSquadStack.ai · OA
  • Maximum Redundancy After One Segment FlipBloomberg LP · OABloomberg LP interview questions
  • Substrings Without a Target SubsequencePhonePe · OAPhonePe interview questions
  • Minimum Edit-Distance String for Each QueryTarget · OA
  • Longest Subsequence That Is a SubstringWells Fargo · OAWells Fargo interview questions
See AXQ Capital hiring insights
Saved
class Solution {
    public int longestPalindromeSubseq(String s) {
        // Write your code here.
    }
}
Checking account…