Minimum characters to be deleted from the end to make given two strings equal | C ++ Program to count minimum number of characters to be deleted to make the 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 Program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int minDel ( string s1 , string s2 ) { int i = 0 ; while ( i < min ( s1 . length ( ) , s2 . length ( ) ) ) { if ( s1 [ i ] != s2 [ i ] ) { break ; } i ++ ; } int ans = ( s1 . length ( ) - i ) + ( s2 . length ( ) - i ) ; return ans ; } int main ( ) { string s1 = " geeks " , s2 = " geeksfor " ; cout << minDel ( s1 , s2 ) << endl ; }