Measure the Longest Palindromic Subsequence. Return the largest length of a palindrome obtainable from s by deleting any number of characters while preserving the order of the characters that remain.
### Problem
Return the largest length of a palindrome obtainable from s by deleting any number of characters while preserving the order of the characters that remain. The chosen characters need not be contiguous.
```cpp
class Solution {
public:
int longestPalindromeSubseq(string s);
};
```
### Examples
**Example 1:**
```text
s = "agbdba"
Output: 5
Explanation: "abdba" is a palindromic subsequence.
```
**Example 2:**
```text
s = "abc"
Output: 1
Explanation: Every palindrome subsequence has one character.
```
### Constraints
- String size: 1..1000 characters, all English lowercase.
### Clarifying Questions
Distinguish subsequences from substrings and justify the endpoint recurrence and its interval bases.
```hint Read the boundary condition
What changes when the two endpoints of an interval are equal?
```
### Contract considerations
Distinguish subsequences from substrings and justify the endpoint recurrence and its interval bases.
Overview: Measure the Longest Palindromic Subsequence. Return the largest length of a palindrome obtainable from s by deleting any number of characters while preserving the order of the characters that remain.
Return the largest length of a palindrome obtainable from s by deleting any number of characters while preserving the order of the characters that remain. The chosen characters need not be contiguous.
class Solution {
public:
int longestPalindromeSubseq(string s);
};
Examples
Example 1:
s = "agbdba"
Output: 5
Explanation: "abdba" is a palindromic subsequence.
Example 2:
s = "abc"
Output: 1
Explanation: Every palindrome subsequence has one character.
Constraints
String size: 1..1000 characters, all English lowercase.
Clarifying Questions Guidance
Distinguish subsequences from substrings and justify the endpoint recurrence and its interval bases.
Contract considerations
Distinguish subsequences from substrings and justify the endpoint recurrence and its interval bases.