Minimum number of deletions to make a string palindrome | function definition ; base cases ; checking the ndesired condition ; if yes increment the cunt ; if no ; return the value form the table ; else store the max tranforamtion from the subsequence ; return the dp [ - 1 ] [ - 1 ] ;  ; initialize the array with - 1
def transformation ( s1 , s2 , i , j , dp ) : NEW_LINE INDENT if i >= len ( s1 ) or j >= len ( s2 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if s1 [ i ] == s2 [ j ] : NEW_LINE INDENT dp [ i ] [ j ] = 1 + transformation ( s1 , s2 , i + 1 , j + 1 , dp ) NEW_LINE DEDENT if dp [ i ] [ j ] != - 1 : NEW_LINE INDENT return dp [ i ] [ j ] NEW_LINE DEDENT else : NEW_LINE INDENT dp [ i ] [ j ] = max ( transformation ( s1 , s2 , i , j + i , dp ) , transformation ( s1 , s2 , i + 1 , j , dp ) ) NEW_LINE DEDENT return dp [ - 1 ] [ - 1 ] NEW_LINE DEDENT s1 = " geeksforgeeks " NEW_LINE s2 = " geeks " NEW_LINE i = 0 NEW_LINE j = 0 NEW_LINE / * Driver code * / NEW_LINE dp = [ [ - 1 for _ in range ( len ( s1 ) + 1 ) ] for _ in range ( len ( s2 ) + 1 ) ] NEW_LINE print ( " MINIMUM ▁ NUMBER ▁ OF ▁ DELETIONS : ▁ " , len ( s1 ) - transformation ( s1 , s2 , 0 , 0 , dp ) , end = " ▁ " ) NEW_LINE print ( " MINIMUM ▁ NUMBER ▁ OF ▁ INSERTIONS : ▁ " , len ( s2 ) - transformation ( s1 , s2 , 0 , 0 , dp ) , end = " ▁ " ) NEW_LINE print ( " LCS ▁ LENGTH : ▁ " , transformation ( s1 , s2 , 0 , 0 , dp ) ) NEW_LINE