Let a range be an array of two integers: the start
and the end
(e.g. [40, 42]
).
Having two arrays of ranges (which are sorted), I want to find the optimal way to calculate their intersection (which will result into another array of ranges):
A = [[1, 3], [7, 9], [12, 18]]
B = [[2, 3], [4,5], [6,8], [13, 14], [16, 17]]
Intersection:
[[2, 3], [7, 8], [13, 14], [16, 17]]
What is the optimal algorithm for this?
The naive way would be to check each one with all the other ones, but that's obviously not optimal.
I found a similar question asking for the same thing in VBA: Intersection of two arrays of ranges
Let a range be an array of two integers: the start
and the end
(e.g. [40, 42]
).
Having two arrays of ranges (which are sorted), I want to find the optimal way to calculate their intersection (which will result into another array of ranges):
A = [[1, 3], [7, 9], [12, 18]]
B = [[2, 3], [4,5], [6,8], [13, 14], [16, 17]]
Intersection:
[[2, 3], [7, 8], [13, 14], [16, 17]]
What is the optimal algorithm for this?
The naive way would be to check each one with all the other ones, but that's obviously not optimal.
I found a similar question asking for the same thing in VBA: Intersection of two arrays of ranges
Share Improve this question edited Mar 25, 2018 at 10:46 Salman Arshad 272k84 gold badges442 silver badges534 bronze badges asked Mar 23, 2018 at 16:02 Ionică BizăuIonică Bizău 113k93 gold badges307 silver badges487 bronze badges 11- How do you get those A, B, and intersection arrays?