Find if string is K | Java program to find if given string is K - Palindrome or not ; find if given string is K - Palindrome or not ; Create a table to store results of subproblems ; Fill dp [ ] [ ] in bottom up manner ; If first string is empty , only option is to remove all characters of second string ; Min . operations = j ; If second string is empty , only option is to remove all characters of first string ; Min . operations = i ; If last characters are same , ignore last character and recur for remaining string ; If last character are different , remove it and find minimum ; Remove from str1 Remove from str2 ; Returns true if str is k palindrome . ;  ; Driver program
class GFG { static int isKPalDP ( String str1 , String str2 , int m , int n ) { int dp [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( i == 0 ) { dp [ i ] [ j ] = j ; } else if ( j == 0 ) { dp [ i ] [ j ] = i ; } else if ( str1 . charAt ( i - 1 ) == str2 . charAt ( j - 1 ) ) { dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ; } else { dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ; } } } return dp [ m ] [ n ] ; } static boolean isKPal ( String str , int k ) { String revStr = str ; revStr = reverse ( revStr ) ; int len = str . length ( ) ; return ( isKPalDP ( str , revStr , len , len ) <= k * 2 ) ; } static String reverse ( String str ) { StringBuilder sb = new StringBuilder ( str ) ; sb . reverse ( ) ; return sb . toString ( ) ; } public static void main ( String [ ] args ) { String str = " acdcb " ; int k = 2 ; if ( isKPal ( str , k ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }