Minimum flips required to form given binary string where every flip changes all bits to its right as well | Java program for the above approach ; 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
import java . util . Arrays ; public class GFG { public static int minFlips ( String target ) { char curr = '1' ; int count = 0 ; for ( int i = 0 ; i < target . length ( ) ; i ++ ) { if ( target . charAt ( i ) == curr ) { count ++ ; curr = ( char ) ( 48 + ( curr + 1 ) % 2 ) ; } } return count ; } public static void main ( String args [ ] ) { String S = "011000" ; System . out . println ( minFlips ( S ) ) ; } }