752. Longest Palindromic Subsequence II
Given a string s, return the length of the longest palindromic subsequence in s that satisfy following criteria :
- It has even length
- No two consecutive characters are equal, except for middle ones
A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.
A palindrome is a sequence that reads the same forward and backward.
Example 1:
Input: s = "bbabab"
Output: 4
Explanation:
The longest good palindromic subsequence of s is "baab".
Example 2:
Input: s = "dcbccacdb"
Output: 4
Explanation:
The longest good palindromic subsequence of s is "dccd".
Now Your Turn!
Pick the correct output for the given inputInput: s = "aabceecbaa"
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= s.length <= 250
- s consists of lowercase English letters.