Minimum characters to be deleted from the end to make given two strings equal | Function that finds minimum character required to be deleted ; Iterate in the strings ; Check if the characters are not equal ; Return the result ; Driver code
def minDel ( s1 , s2 ) : NEW_LINE INDENT i = 0 ; NEW_LINE while ( i < min ( len ( s1 ) , len ( s2 ) ) ) : NEW_LINE INDENT if ( s1 [ i ] != s2 [ i ] ) : NEW_LINE INDENT break ; NEW_LINE DEDENT i += 1 ; NEW_LINE DEDENT ans = ( ( len ( s1 ) - i ) + ( len ( s2 ) - i ) ) ; NEW_LINE return ans ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT s1 = " geeks " ; NEW_LINE s2 = " geeksfor " ; NEW_LINE print ( minDel ( s1 , s2 ) ) ; NEW_LINE DEDENT