Periodic Binary String With Minimum Period and a Given Binary String as Subsequence . | Java implementation to find the periodic string with minimum period ; 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
class GFG { static void findPeriodicString ( String S ) { int l = 2 * S . length ( ) ; int count = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( S . charAt ( i ) == '1' ) count ++ ; } if ( count == S . length ( ) count == 0 ) System . out . println ( S ) ; else { char arr [ ] = new char [ l ] ; for ( int i = 0 ; i < l ; i += 2 ) { arr [ i ] = '1' ; arr [ i + 1 ] = '0' ; } for ( int i = 0 ; i < l ; i ++ ) System . out . print ( arr [ i ] ) ; System . out . println ( ) ; } } public static void main ( String [ ] args ) { String S = "1111001" ; findPeriodicString ( S ) ; } }