Minimum number of deletions to make a string palindrome | Function definition ; Base cases ; Checking the ndesired condition ; If yes increment the cunt ; If no ; Return the value form the table ; Else store the max tranforamtion from the subsequence ; Return the dp [ - 1 ] [ - 1 ] ; Driver code ; Initialize the array with - 1
using System ; class GFG { static int [ , ] dp = new int [ 2000 , 2000 ] ; static int transformation ( string s1 , string s2 , int i , int j ) { if ( i >= ( s1 . Length ) || j >= ( s2 . Length ) ) { return 0 ; } if ( s1 [ i ] == s2 [ j ] ) { dp [ i , j ] = 1 + transformation ( s1 , s2 , i + 1 , j + 1 ) ; } if ( dp [ i , j ] != - 1 ) { return dp [ i , j ] ; } else { dp [ i , j ] = Math . Max ( transformation ( s1 , s2 , i , j + i ) , transformation ( s1 , s2 , i + 1 , j ) ) ; } return dp [ s1 . Length - 1 , s2 . Length - 1 ] ; } static public void Main ( ) { string s1 = " geeksforgeeks " ; string s2 = " geeks " ; for ( int m = 0 ; m < 2000 ; m ++ ) { for ( int n = 0 ; n < 2000 ; n ++ ) { dp [ m , n ] = - 1 ; } } Console . WriteLine ( " MINIMUM ▁ NUMBER ▁ OF ▁ DELETIONS : ▁ " + ( s1 . Length - transformation ( s1 , s2 , 0 , 0 ) ) ) ; Console . WriteLine ( " MINIMUM ▁ NUMBER ▁ OF ▁ INSERTIONS : ▁ " + ( s2 . Length - transformation ( s1 , s2 , 0 , 0 ) ) ) ; Console . WriteLine ( " LCS ▁ LENGTH : ▁ " + transformation ( s1 , s2 , 0 , 0 ) ) ; } }