Minimum substring flips required to convert given binary string to another | C # 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
using System ; class GFG { static void findMinimumOperations ( string a , string b ) { int step = 0 ; int last_index = 0 ; while ( a . Equals ( b ) == false ) { for ( int i = 0 ; i < a . Length ; i ++ ) { if ( a [ i ] != b [ i ] ) { last_index = i ; } } char [ ] ch = a . ToCharArray ( ) ; for ( int i = 0 ; i <= last_index ; i ++ ) { if ( ch [ i ] == '0' ) { ch [ i ] = '1' ; } else { ch [ i ] = '0' ; } } a = new string ( ch ) ; step ++ ; } Console . WriteLine ( step ) ; } public static void Main ( ) { string A = "101010" ; string B = "110011" ; findMinimumOperations ( A , B ) ; } }