Longest Palindromic Subsequence

Hard

Given a string s, return the length of the longest palindromic subsequence (characters keep their order but need not be adjacent).

Example 1

longestPalindromeSubseq()
Input
s = "bbbab"
Output
4

Why

"bbbb"

Example 2

longestPalindromeSubseq()
Input
s = "cbbd"
Output
2
Constraints
1 <= s.length <= 1000
`s` consists of lowercase English letters.

Topics

Dynamic ProgrammingStrings

Implement longestPalindromeSubseq in the editor and return the answer — printing it is never graded.