text: Find Bit whose minimum sequence flips makes all bits same | C ++ program to find which bit sequence to be flipped ; Function to check which bit is to be flipped ; variable to store first and last character of string ; Check if first and last characters are equal , if yes , then return the character which is not at last ; else return last ; Driver Code
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; char bitToBeFlipped ( string s ) { char last = s [ s . length ( ) - 1 ] ; char first = s [ 0 ] ; if ( last == first ) { if ( last == '0' ) { return '1' ; } else { return '0' ; } } else if ( last != first ) { return last ; } } int main ( ) { string s = "1101011000" ; cout << bitToBeFlipped ( s ) << endl ; return 0 ; }