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: < ? php function bitToBeFlipped ( $ s ) { $ last = $ s [ strlen ( $ s ) - 1 ] ; $ first = $ s [ 0 ] ; if ( $ last == $ first ) { if ( $ last == '0' ) { return '1' ; } else { return '0' ; } } else if ( $ last != $ first ) { return $ last ; } } $ s = "1101011000" ; echo bitToBeFlipped ( $ s ) ; ? >