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 Code
< ? php function isConvertible ( $ str1 , $ str2 , $ k ) { if ( ( strlen ( $ str1 ) + strlen ( $ str2 ) ) < $ k ) return true ; $ commonLength = 0 ; for ( $ i = 0 ; $ i < min ( strlen ( $ str1 ) , strlen ( $ str2 ) ) ; $ i ++ ) { if ( $ str1 == $ str2 ) $ commonLength += 1 ; else break ; } if ( ( $ k - strlen ( $ str1 ) - strlen ( $ str2 ) + 2 * $ commonLength ) % 2 == 0 ) return true ; return false ; } $ str1 = " geek " ; $ str2 = " geek " ; $ k = 7 ; if ( isConvertible ( $ str1 , $ str2 , $ k ) ) echo " Yes " . " STRNEWLINE " ; else echo " No " . " STRNEWLINE " ; $ str1 = " geeks " ; $ str2 = " geek " ; $ k = 5 ; if ( isConvertible ( $ str1 , $ str2 , $ k ) ) echo " Yes " . " STRNEWLINE " ; else echo " No " . " STRNEWLINE " ; ? >