Generate string with Hamming Distance as half of the hamming distance between strings A and B | Function to find the required string ; Find the hamming distance between A and B ; If distance is odd , then resultant string is not possible ; Make the resultant string ; To store the final string ; Pick k characters from each string ; Pick K characters from string B ; Pick K characters from string A ; Append the res characters from string to the resultant string ; Print the resultant string ; Driver 's Code  ; Function to find the resultant string
def findString ( A , B ) : NEW_LINE INDENT dist = 0 ; NEW_LINE for i in range ( len ( A ) ) : NEW_LINE INDENT if ( A [ i ] != B [ i ] ) : NEW_LINE INDENT dist += 1 ; NEW_LINE DEDENT DEDENT if ( dist & 1 ) : NEW_LINE INDENT print ( " Not ▁ Possible " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT res = " " ; NEW_LINE K = dist // 2 ; NEW_LINE for i in range ( len ( A ) ) : NEW_LINE INDENT if ( A [ i ] != B [ i ] and K > 0 ) : NEW_LINE INDENT res += B [ i ] ; NEW_LINE K -= 1 ; NEW_LINE DEDENT elif ( A [ i ] != B [ i ] ) : NEW_LINE INDENT res += A [ i ] ; NEW_LINE DEDENT else : NEW_LINE INDENT res += A [ i ] ; NEW_LINE DEDENT DEDENT print ( res ) ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT A = "1001010" ; NEW_LINE B = "0101010" ; NEW_LINE findString ( A , B ) ; NEW_LINE DEDENT