Given a range f.e. :
range : 1 4
there are 3 lists of pairs that 'fill' this range w/o gaps. Call it a 'chain'
chain1: 1 2, 2 3, 3 4
chain2: 1 2, 2 4
chain3: 1 3, 3 4
the following lists of pairs fail to fill the range, so it is not a chain :
1 2 <= missing 2 3, 3 4 OR 2 4
1 3 <= missing 3 4
1 2, 3 4 <= missing 2 3
1 2, 2 3 <= missing 3 4
2 3, 3 4 <= missing 1 2
Now the question is given a random list of pairs and a range how can I find is there a combination of pairs that makes a CHAIN.
Pairs do not repeat, are always (lower-value, higher-value) and never overlap i.e. this is never an input [ 1 3, 2 4 ]
In addition I can pre-filter only the pairs that are within the range, so f.e. you dont have to worry about pairs like : 4 6, 7 9, 0 1 ...
update ... this is also valid input
chain: 1 2, 1 3, 3 4
chain: 1 2, 1 3, 1 4
chain: 1 2, 2 4, 3 4
i.e a pair can subsume another .... this breaks the sort-and-loop idea
implemented the Union-Find algo from here in python ..
only cares about first two elements of the tuple
here