Check if 2 * K + 1 non | Function to check if the string S can be obtained by ( K + 1 ) non - empty substrings whose concatenation and concatenation of the reverse of these K strings ; Stores the size of the string ; If n is less than 2 * k + 1 ; Stores the first K characters ; Stores the last K characters ; Reverse the string ; If both the strings are equal ; Driver Code
function checkString ( s , k ) { let n = s . length ; if ( 2 * k + 1 > n ) { document . write ( " " ) ; return ; } let a = s . substr ( 0 , k ) ; let b = s . substr ( n - k , k ) ; b . split ( " " ) . reverse ( ) . join ( " " ) if ( a == b ) document . write ( " " ) ; else document . write ( " " ) ; } let S = " " ; let K = 1 ; checkString ( S , K ) ;