Find if string is K | Find if given string is K - Palindrome or not ; If first string is empty , the only option is to remove all characters of second string ; If second string is empty , the only option is to remove all characters of first string ; If last characters of two strings are same , ignore last characters and get count for remaining strings . ; If last characters are not same , 1. Remove last char from str1 and recur for m - 1 and n 2. Remove last char from str2 and recur for m and n - 1 Take minimum of above two operations res = 1 + min ( isKPalRec ( str1 , str2 , m - 1 , n ) , Remove from str1 ( isKPalRec ( str1 , str2 , m , n - 1 ) ) ) Remove from str2 ; Returns true if str is k palindrome . ; Driver program
def isKPalRec ( str1 , str2 , m , n ) : NEW_LINE INDENT if not m : return n NEW_LINE if not n : return m NEW_LINE if str1 [ m - 1 ] == str2 [ n - 1 ] : NEW_LINE INDENT return isKPalRec ( str1 , str2 , m - 1 , n - 1 ) NEW_LINE DEDENT return res NEW_LINE DEDENT def isKPal ( string , k ) : NEW_LINE INDENT revStr = string [ : : - 1 ] NEW_LINE l = len ( string ) NEW_LINE return ( isKPalRec ( string , revStr , l , l ) <= k * 2 ) NEW_LINE DEDENT string = " acdcb " NEW_LINE k = 2 NEW_LINE print ( " Yes " if isKPal ( string , k ) else " No " ) NEW_LINE