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: using System ; class GfG { static 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 ; } return last ; } public static void Main ( ) { string s = "1101011000" ; Console . WriteLine ( bitToBeFlipped ( s ) ) ; } }