kpalindrome
A k-palindrome is a string that can be transformed into a palindrome by deleting at most k characters. In this sense, the property is about how far a given string is from being a palindrome under deletions.
Equivalently, a string s is a k-palindrome if there exists a subsequence of s that is a
A useful relation for computation is that the minimum deletions to make s a palindrome equals n
Dynamic programming provides practical algorithms. One approach computes LPS for all substrings, giving O(n^2) time and
- if s[i] == s[j], dp[i][j] = dp[i+1][j−1];
- else, dp[i][j] = 1 + min(dp[i+1][j], dp[i][j−1]).
Variants of the definition may permit insertions as well as deletions, or focus on similar measures of
Examples: s = "abbda" has n = 5 and LPS length 4, so it is a 1-palindrome. s =