Periodic Binary String With Minimum Period and a Given Binary String as Subsequence . | Function to find the periodic string with minimum period ; Print the S if it consists of similar elements ; Find the required periodic with period 2 ; Driver Code
def findPeriodicString ( S ) : NEW_LINE INDENT l = 2 * len ( S ) NEW_LINE count = 0 NEW_LINE for i in range ( len ( S ) ) : NEW_LINE INDENT if ( S [ i ] == '1' ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT if ( count == len ( S ) or count == 0 ) : NEW_LINE INDENT print ( S ) NEW_LINE DEDENT else : NEW_LINE INDENT arr = [ '0' ] * l NEW_LINE for i in range ( 0 , l , 2 ) : NEW_LINE INDENT arr [ i ] = '1' NEW_LINE arr [ i + 1 ] = '0' NEW_LINE DEDENT for i in range ( l ) : NEW_LINE INDENT print ( arr [ i ] , end = " " ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT S = "1111001" NEW_LINE findPeriodicString ( S ) NEW_LINE DEDENT