Minimum characters to be deleted from the end to make given two strings equal | Java 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 code
class GFG { static int minDel ( String s1 , String s2 ) { int i = 0 ; while ( i < Math . min ( s1 . length ( ) , s2 . length ( ) ) ) { if ( s1 . charAt ( i ) != s2 . charAt ( i ) ) { break ; } i ++ ; } int ans = ( ( s1 . length ( ) - i ) + ( s2 . length ( ) - i ) ) ; return ans ; } public static void main ( String [ ] args ) { String s1 = " geeks " ; String s2 = " geeksfor " ; System . out . println ( minDel ( s1 , s2 ) ) ; } }