Given two lists of 1s and 0s called A and B of the same length, I want to determine if there is some way of inserting exactly n 1s or 0s into A and exactly n 1s or 0s into B to make them the same list. n will always be less than the lengths of the lists.
For example, set n = 2.  Let A = [0,0,1,1,0,0] and B = [0,1,0,1,0,1]. We can transform A into [0,1,0,1,0,1,0,0] by inserting a 1 and a 0. B can be made into the same list by add two 0s at the right hand end.   
Is there a known way to compute such a function
def match(A,B,n):
    return True if A and B are exactly insertion distance n from a common list   
?