Minimum characters to be deleted from the beginning of two strings to make them equal | Java Program to count minimum number of characters to be deleted from the beginning of the two strings 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
import java . util . * ; class GFG { static int minDel ( String s1 , String s2 ) { int i = s1 . length ( ) ; int j = s2 . length ( ) ; while ( i > 0 && j > 0 ) { if ( s1 . charAt ( i - 1 ) != s2 . charAt ( j - 1 ) ) { break ; } i -- ; j -- ; } return i + j ; } public static void main ( String args [ ] ) { String s1 = " geeksforgeeks " , s2 = " peeks " ; System . out . print ( minDel ( s1 , s2 ) ) ; } }