

str = “ababba”, k = 3.
In this example, If we remove one ‘b’ from the 3rd position, then the final string will be “ababa” which is a palindrome.
Hence the answer will be True.
The first line contains a single integer ‘T’ denoting the number of test cases, then each test case follows:
The first line of each test case contains a single integer ‘k’, denoting the maximum number of characters you can remove from the string.
The second line of the test case contains the string “str”.
For each test case, print whether the following string is a K-Palindrome or not.
Output for each test case will be printed in a separate line.
You are not required to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 10
1 <= |S| <= 1000
1 <= k <= 30
Time limit: 1 sec
In this approach, we will make a copy of the original string and reverse it and recursively check if the current characters are equal or not.
The steps are as follows:
In this approach, we will make a copy of the original string and reverse it and recursively check if the current characters are equal or not, by doing so, we are checking the LCS of these two strings, which will eventually be the longest palindromic substring, as the second string is reverse of the first string.
The steps are as follows:
As the value of k is very small, we can take advantage of that fact and reduce its time complexity. The approach is simple. We can only delete a maximum of ‘k’ characters from the current string. This means any position which is more than ‘k’ position away from the current ‘i’ cannot be updated. Hence, we don't have to update the dp array for the size greater than ‘i’ + ‘k’ or less than ‘i’ - ‘k’.
The steps are as follows: