Check if a string can be split into two substrings such that one substring is a substring of the other | Function to check if a String can be divided into two subStrings such that one subString is subString of the other ; Store the last character of S ; Traverse the characters at indices [ 0 , N - 2 ] ; Check if the current character is equal to the last character ; If true , set f = 1 ; Break out of the loop ; Given String , S ; Store the size of S ; Function Call
function splitString ( S , N ) { var c = S . charAt ( N - 1 ) ; var f = 0 ; for ( var i = 0 ; i < N - 1 ; i ++ ) { if ( S . charAt ( i ) == c ) { f = 1 ; break ; } } if ( f > 0 ) document . write ( " " ) ; else document . write ( " " ) ; } var S = " " ; var N = S . length ; splitString ( S , N ) ;