text: Find Bit whose minimum sequence flips makes all bits same | 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: function bitToBeFlipped ( s ) { let last = s [ s . length - 1 ] ; let first = s [ 0 ] ; if ( last == first ) { if ( last == ' ' ) { return ' ' ; } else { return ' ' ; } } else if ( last != first ) { return last ; } } let s = " " ; document . write ( bitToBeFlipped ( s ) , ' ' ) ;