Check if all bits can be made same by flipping two consecutive bits | Java program for the above approach ; Function to check if Binary string can be made equal ; Counting occurence of zero and one in binary string ; From above observation ; Driver code
class GFG { static String canMake ( String s ) { int o = 0 , z = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) - '0' == 1 ) o ++ ; else z ++ ; } if ( o % 2 == 1 && z % 2 == 1 ) return " NO " ; else return " YES " ; } public static void main ( String [ ] args ) { String s = "01011" ; System . out . println ( canMake ( s ) ) ; } }