Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Set Intersection algorithm O(nlogn) time. Code in Python.

View Intersection.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
from itertools import chain
 
intersection = []
 
sets = [[0,4,5,2,1],[1,3,6,2,4],[4,1,2,5,7,0]]
 
merged = list(chain.from_iterable(sets))
 
merged.sort()
 
i = 0
while i < (len(merged)-(len(sets)-1)):
sub = merged[i:(i+len(sets))]
if sub[0] == sub[len(sub)-1]:
intersection.append(sub[0])
i += (len(sub)-1)
i += 1
 
print intersection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.