Periodic Binary String With Minimum Period and a Given Binary String as Subsequence . | Function to find the periodic string with minimum period ; Print the string S if it consists of similar elements ; Find the required periodic string with period 2 ; Driver Code
function findPeriodicString ( S ) { let l = 2 * S . length ; let count = 0 ; for ( let i = 0 ; i < S . length ; i ++ ) { if ( S [ i ] == ' ' ) count ++ ; } if ( count == S . length count == 0 ) document . write ( S + " " ) ; else { let arr = new Array ( l ) ; for ( let i = 0 ; i < l ; i += 2 ) { arr [ i ] = ' ' ; arr [ i + 1 ] = ' ' ; } for ( let i = 0 ; i < l ; i ++ ) document . write ( arr [ i ] ) ; document . write ( " " ) ; } } let S = " " ; findPeriodicString ( S ) ;