FastPrepLongest Palindromic Subsequence
Problems/Longest Palindromic Subsequence

Longest Palindromic Subsequence

Amazon logoAmazon● MediumONSITE INTERVIEW
QuestionFunctionExamples

Problem statement

Source note: This problem is backed by a real Amazon onsite interview report. The report directly named Longest Palindromic Subsequence, but it did not include the exact function interface, examples, or constraints. The core task match is about 95%.

Given a string s, return the length of its longest subsequence that reads the same from left to right and right to left.

A subsequence keeps the relative order of selected characters but does not need to use contiguous positions.

Function

longestPalindromeSubseq(s: String) → int

Examples

Example 1

s = "bbbab"return = 4

One longest palindromic subsequence is bbbb.

Example 2

s = "cbbd"return = 2

More Amazon problems

  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
See Amazon hiring insights
Saved
class Solution {
    public int longestPalindromeSubseq(String s) {
      // write your code here
    }
}
Checking account…