title: Algorithms for finding the intersections of intervals
body: <p>I am wondering how I can find the number of intervals that intersect with the ones before it.
  we want to know he number of pairs (i, j), with i &lt; j, such that Internal i ∩ interval j = ∅.
  For example  for the intervals [2, 4], [1, 6], [5, 6], [0, 4], the output should be 2. from [2,4] [5,6] and [5,6] [0,4].</p>
  
  <p>So now we have 1 set of intervals with size n all containing a point a, then we add another set of intervals size n as well, and all of the intervals are to the right of a. Can you do this in O(nlgn) and O(nlg^2n)?</p>