Minimum substring flips required to convert given binary string to another | Java program for the above approach ; Function that finds the minimum number of operations required such that String A and B are the same ; Stores the count of steps ; Stores the last index whose bits are not same ; Iterate until both String are unequal ; Check till end of String to find rightmost unequals bit ; Update the last index ; Flipping characters up to the last index ; Flip the bit ; Increasing steps by one ; Print the count of steps ; Driver Code ; Given Strings A and B ; Function Call
import java . util . * ; class GFG { static void findMinimumOperations ( char [ ] a , char [ ] b ) { int step = 0 ; int last_index = 0 ; while ( ! Arrays . equals ( a , b ) ) { for ( int i = 0 ; i < a . length ; i ++ ) { if ( a [ i ] != b [ i ] ) { last_index = i ; } } for ( int i = 0 ; i <= last_index ; i ++ ) { a [ i ] = ( a [ i ] == '0' ) ? '1' : '0' ; } step ++ ; } System . out . print ( step ) ; } public static void main ( String [ ] args ) { String A = "101010" , B = "110011" ; findMinimumOperations ( A . toCharArray ( ) , B . toCharArray ( ) ) ; } }