Minimum number of deletions to make a string palindrome | Java program for above approach ; Function to return minimum Element between two values ; Utility function for calculating Minimum element to delete ; Condition to compare characters ; Recursive function call ; Return value , increamenting by 1 ; Function to calculate the minimum Element required to delete for Making string pelindrom ; Utility function call ; Driver Code
import java . io . * ; import java . util . * ; class GFG { public static int min ( int x , int y ) { return ( x < y ) ? x : y ; } public static int utility_fun_for_del ( String str , int i , int j ) { if ( i >= j ) return 0 ; if ( str . charAt ( i ) == str . charAt ( j ) ) { return utility_fun_for_del ( str , i + 1 , j - 1 ) ; } return 1 + Math . min ( utility_fun_for_del ( str , i + 1 , j ) , utility_fun_for_del ( str , i , j - 1 ) ) ; } public static int min_ele_del ( String str ) { return utility_fun_for_del ( str , 0 , str . length ( ) - 1 ) ; } public static void main ( String [ ] args ) { String str = " abefbac " ; System . out . println ( " Minimum ▁ element ▁ of ▁ deletions ▁ = ▁ " + min_ele_del ( str ) ) ; } }