Minimum flips required to form given binary string where every flip changes all bits to its right as well | Function to return the count of minimum flips required ; If curr occurs in the final string ; Switch curr to '0' if '1' or vice - versa ; Driver code
function minFlips ( target ) { let curr = ' ' ; let count = 0 ; for ( let i = 0 ; i < target . length ; i ++ ) { if ( target [ i ] == curr ) { count ++ ; curr = String . fromCharCode ( 48 + ( curr . charCodeAt ( ) + 1 ) % 2 ) ; } } return count ; } let S = " " ; document . write ( minFlips ( S ) ) ;