Minimum substring flips required to convert given binary string to another | 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 ; Given strings A and B ; Function Call
function findMinimumOperations ( a , b ) { var step = 0 ; var last_index = 0 ; while ( a !== b ) { for ( var i = 0 ; i < a . length ; i ++ ) { if ( a [ i ] !== b [ i ] ) { last_index = i ; } } var ch = a . split ( " " ) ; for ( var i = 0 ; i <= last_index ; i ++ ) { if ( ch [ i ] === " " ) { ch [ i ] = " " ; } else { ch [ i ] = " " ; } } a = ch . join ( " " ) ; step ++ ; } document . write ( step ) ; } var A = " " ; var B = " " ; findMinimumOperations ( A , B ) ;