human
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"
How can the above be solved in Python?
assistant
#Here is code to minimum number of deletions to make a string palindrome and the other steps required.
 def transformation ( s1 , s2 , i , j , dp ) :
	if i >= len ( s1 ) or j >= len ( s2 ) :
		return 0
	if s1 [ i ] == s2 [ j ] :
		dp [ i ] [ j ] = 1 + transformation ( s1 , s2 , i + 1 , j + 1 , dp )
	if dp [ i ] [ j ] != - 1 :
		return dp [ i ] [ j ]
	else :
		dp [ i ] [ j ] = max ( transformation ( s1 , s2 , i , j + i , dp ) , transformation ( s1 , s2 , i + 1 , j , dp ) )
	return dp [ - 1 ] [ - 1 ]
s1 = " geeksforgeeks "
s2 = " geeks "
i = 0
j = 0
/ * Driver code * /
dp = [ [ - 1 for _ in range ( len ( s1 ) + 1 ) ] for _ in range ( len ( s2 ) + 1 ) ]
print ( " MINIMUM ▁ NUMBER ▁ OF ▁ DELETIONS : ▁ " , len ( s1 ) - transformation ( s1 , s2 , 0 , 0 , dp ) , end = " ▁ " )
print ( " MINIMUM ▁ NUMBER ▁ OF ▁ INSERTIONS : ▁ " , len ( s2 ) - transformation ( s1 , s2 , 0 , 0 , dp ) , end = " ▁ " )
print ( " LCS ▁ LENGTH : ▁ " , transformation ( s1 , s2 , 0 , 0 , dp ) )