Virtual onsite round 1:
At first the interviewer asks me how to sort by x in a list of pair (x, y)
a.sort(key= lambda x:x[0])
There are 2 lists A and B containing (x, y) pairs of the same length,
A= [(x1, y1), (x2, y2),...,(xn, yn)]
B= [(x'1, y'1), (x'2, y'2),...,(x'n, y'n)]
x in A and B are nondecreasing order
x1<=x2<=x3 ...<=xn
x'1<=x'2<=x'3 ...<=x'n
for index 0<=i<n
we also want to make a[i][1]<b[i][1]
What do we do?
test case1
a= [(1, 0), (1, 1), (1, 7), (1, 5) ]
b= [(1, 7), (1, 9), (2, 3), (4, 1) ]
#in this case you can rearrange a
a= [(1, 5), (1, 7), (1, 1), (1, 0)]
b= [(1, 7), (1, 9), (2, 3), (4, 1) ]
test case2
a= [(1, 0), (2, 1), (3, 7), (3, 5) ]
b= [(2, 7), (2, 9), (2, 3), (2, 1) ]
#in this case you can rearrange b
a= [(1, 0), (2, 1), (3, 7), (3, 5) ]
b= [(2, 1), (2, 3), (2, 9), (2, 7) ]
#invalid test case
a = [(1, 0), (2, 1), (3, 7), (4, 5)]
b = [(2, 7), (3, 0), (4, 3), (5, 1)]
If you cannot find valid a and b, raise exception
I can't come up with optimal solution...
Does any one have any idea?