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