title: Overlapping time intervals WITHOUT for/while loops
body: <p>The best way to ask my question is via a clear example. Consider 2 timelines (e.g. time in seconds) A and B where the intervals for each timeline are:</p>
  
  <pre><code>intervals_a = 
     0 1
     1 4
     4 7
     7 9
  
  intervals_b = 
     0 2
     2 3
     3 5
     5 8
  </code></pre>
  
  <p>Notice that the first a-interval overlaps the first b-interval. The second a-interval overlaps the first, second, and third b-intervals, and so on.</p>
  
  <p>Ultimately, I need an output which shows the indices of a-intervals which overlap with b-intervals as below:</p>
  
  <pre><code>output = 
     1 1   \\ 1st a-interval overlaps 1st b-interval
     2 1   \\ 2nd a-interval overlaps 1st b-interval
     2 2   \\ 2nd a-interval overlaps 2nd b-interval
     2 3   \\ 2nd a-interval overlaps 3rd b-interval
     3 3   \\ etc...
     3 4
     4 4
  </code></pre>
  
  <p>The big challenge is: The solution cannot contain for/while loops ("why" is irrelevant). Can this be done efficiently using vector / matrix / array / sort or other tools? A MATLAB implementation would be perfect, but any other language is fine. Thanks in advance!</p>