Problem · String

Longest Palindromic Subsequence

Learn this problem
MediumAmazonONSITE INTERVIEW
See Amazon hiring insights

Problem statement

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

drafts saved locally
public int longestPalindromeSubseq(String s) {
  // write your code here
}
s"bbbab"
expected4
checking account