Minimum number of deletions to make a string palindrome | Utility function for calculating Minimum element to delete ; Condition to compare characters ; Recursive function call ; Return value , increamenting by 1 return minimum Element between two values ; Function to calculate the minimum Element required to delete for Making string pelindrom ; Utility function call ; Driver code
def utility_fun_for_del ( Str , i , j ) : NEW_LINE INDENT if ( i >= j ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( Str [ i ] == Str [ j ] ) : NEW_LINE INDENT return utility_fun_for_del ( Str , i + 1 , j - 1 ) NEW_LINE DEDENT return ( 1 + min ( utility_fun_for_del ( Str , i + 1 , j ) , utility_fun_for_del ( Str , i , j - 1 ) ) ) NEW_LINE DEDENT def min_ele_del ( Str ) : NEW_LINE INDENT return utility_fun_for_del ( Str , 0 , len ( Str ) - 1 ) NEW_LINE DEDENT Str = " abefbac " NEW_LINE print ( " Minimum ▁ element ▁ of ▁ deletions ▁ = " , min_ele_del ( Str ) ) NEW_LINE