Converting one string to other using append and delete last operations | Returns true if it is possible to convert str1 to str2 using k operations . ; Case A ( i ) ; finding common length of both string ; Case A ( ii ) - ; Case B - ; driver program
function isConvertible ( str1 , str2 , k ) { if ( ( str1 . length + str2 . length ) < k ) return true ; var commonLength = 0 ; for ( var i = 0 ; i < Math . min ( str1 . length , str2 . length ) ; i ++ ) { if ( str1 [ i ] == str2 [ i ] ) commonLength ++ ; else break ; } if ( ( k - str1 . length - str2 . length + 2 * commonLength ) % 2 == 0 ) return true ; return false ; } var str1 = " " , str2 = " " ; var k = 7 ; if ( isConvertible ( str1 , str2 , k ) ) document . write ( " " ) ; else document . write ( " " ) ; str1 = " " , str2 = " " ; k = 5 ; document . write ( " " ) ; if ( isConvertible ( str1 , str2 , k ) ) document . write ( " " ) ; else document . write ( " " ) ;