We are given two sets of intervals A
and B
. By an interval, I mean an ordered pair of integers such as c(2,5)
. I want to find all pairs of intervals - one from A
and one from B
- that have overlap.
For instance if A and B are as follows:
A=c(c(1,7), c(2,5), c(4, 16))
B=c(c(2,3), c(2,20))
Then FindOverlap(A, B)
should return a matrix like below (the only zero element is because the 3rd interval of A
does not overlap with the first interval of B
):
1 1
1 1
0 1
Do you have any efficient idea?