Find the length of the longest subsequence of a string that reads the same forward and backward.
Given a string s, determine the length of the longest palindromic subsequence in s.
A subsequence is formed by deleting zero or more characters without changing the order of the remaining characters. The subsequence does not need to be contiguous.
Return only the maximum possible length.
s.s contains lowercase English letters unless stated otherwise by the platform.s.Example 1
Input
s = "bbbab"
Output
4
Explanation
One longest palindromic subsequence is "bbbb".
Example 2
Input
s = "cbbd"
Output
2
Explanation
One longest palindromic subsequence is "bb".
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.