In one operation, you can replace the character at any position with the next or previous letter in the alphabet (wrapping around so that 'a' is after
'z'). For example, replacing 'a' with the next letter results in 'b', and replacing 'a' with the previous letter results in 'z'. Similarly, replacing 'z' with the next letter results in 'a', and replacing 'z'
with the previous letter results in 'y'.
Return the length of the longest palindromic subsequence of s that can be obtained after performing at mostk operations.
Input: s ="abced", k =2Output: 3Explanation:
* Replace `s[1]`with the next letter, and `s` becomes `"acced"`.* Replace `s[4]`with the previous letter, and `s` becomes `"accec"`.The subsequence `"ccc"` forms a palindrome of length 3, which is the maximum.
Input: s ="aaazzz", k =4Output: 6Explanation:
* Replace `s[0]`with the previous letter, and `s` becomes `"zaazzz"`.* Replace `s[4]`with the next letter, and `s` becomes `"zaazaz"`.* Replace `s[3]`with the next letter, and `s` becomes `"zaaaaz"`.The entire string forms a palindrome of length 6.
We use dynamic programming to find the longest palindromic subsequence, allowing up to k character changes. For each substring, we track the number of operations used and maximize the palindrome length.