Check if a string can be converted to another given string by removal of a substring | Function to check if S can be converted to T by removing at most one subString from S ; Check if S can be converted to T by removing at most one subString from S ; Stores length of String T ; Stores length of String S ; Iterate over the range [ 0 , M - 1 ] ; Stores Length of the subString { S [ 0 ] , ... , S [ i ] } ; Stores Length of the subString { S [ 0 ] , ... , S [ i ] } ; Stores prefix subString ; Stores suffix subString ; Checking if prefix + suffix == T ; Given String S and T ; Function call
function make_String_S_to_T ( S , T ) { var possible = false ; var M = T . length ; var N = S . length ; for ( i = 0 ; i <= M ; i ++ ) { var prefix_length = i ; var suffix_length = M - i ; var prefix = S . substring ( 0 , prefix_length ) ; var suffix = S . substring ( N - suffix_length , N ) ; if ( ( prefix + suffix ) == ( T ) ) { possible = true ; break ; } } if ( possible ) return " " ; else return " " ; } var S = " " ; var T = " " ; document . write ( make_String_S_to_T ( S , T ) ) ;