Consider two finite lists of positive integers:
A = [1,2,14,15,20,...], where A[i+1]>A[i], for all i B = [4,7,10,16,24,...], where B[i+1]>B[i], for all i
In addition, A[i]==B[i] is false for all i, but len(A) need not equal len(B).
I’m looking for a python solution that returns two modified lists (C,D):
def get_consecutive_alternating(A,B): ... return (C,D)
1) C is a subset of A, and D is a subset of B, such that C,D,C,D,C,D,…,C[N-1],D[N-1] is a consecutive list where N is the length of the lists (i.e. len(C) = len(D)).
2) In the case of multiple solutions, e.g.,
A = [1,10,15]
B = [2,3,5,11,23]
the first element, or lowest integer (since each list is separately sorted), is selected:
C = [1,10,15]
D = [2,11,23]
3) If no solution exists, simply return empty lists, e.g.,
A = [20,30,50]
B = [1,10,15]
Will result in
A = 
B = 
Any help is greatly appreciated. Even if you can just provide me with the name of this algorithm. An actual efficient solution is a bonus!
So far, I have the following
def get_alternating_consecutive_list(A,B): L =  for a in A: found = False for b in B: if a<b and not found: L=L+[a,b] found = True C = L[1::2] D = L[::2] return (C,D)
I’m still testing it for correctness. Here is a setup script:
N_A = random.sample(range(1, 10), 1) N_B = random.sample(range(1, 10), 1) A = random.sample(range(1, 20), N_A) B = random.sample(range(1, 20), N_B) dupes = list(set(A) & set(B)) A = [x for x in A if not any([x == y for y in dupes])] B = [x for x in B if not any([x == y for y in dupes])] A.sort() B.sort()
✓ Extra quality
ExtraProxies brings the best proxy quality for you with our private and reliable proxies
✓ Extra anonymity
Top level of anonymity and 100% safe proxies – this is what you get with every proxy package
✓ Extra speed
1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!
USA proxy location
We offer premium quality USA private proxies – the most essential proxies you can ever want from USA
Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies
Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!
Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!
99,9% servers uptime
Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems
No usage restrictions
You have freedom to use your proxies with every software, browser or website you want without restrictions
Perfect for SEO
We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies
Buy more proxies and get better price – we offer various proxy packages with great deals and discounts
We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!