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
let dp = new Array ( 2000 ) ; function transformation ( s1 , s2 , i , 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 ] ; } let s1 = " " ; let s2 = " " ; let i = 0 ; let j = 0 ; for ( let row = 0 ; row < dp . length ; row ++ ) { dp [ row ] = new Array ( dp . length ) ; for ( let column = 0 ; column < dp . length ; column ++ ) { dp [ row ] [ column ] = - 1 ; } } document . write ( " " + ( s1 . length - transformation ( s1 , s2 , 0 , 0 ) ) ) ; document . write ( " " + ( s2 . length - transformation ( s1 , s2 , 0 , 0 ) ) ) ; document . write ( " " + transformation ( s1 , s2 , 0 , 0 ) ) ;