title: How to build a data-structure to support some range queries
body: <p>An interval is defined by start and end.</p>
  
  <blockquote>
    <p>Given a set of possibly overlapping intervals in a range[say, 0-999],
    build a data structure to support following range queries in optimal
    time complexity</p>
  </blockquote>
  
  <p>.</p>
  
  <p><strong>Overlap(start, end)</strong> = set of all intervals that overlap with [start, end]</p>
  
  <p><strong>Within(start, end)</strong> = set of all intervals that lie within [start, end]</p>
  
  <p>Where,</p>
  
  <pre><code>Intervals I1[start1, end1], I2[start2, end2] are said to overlap with  each other iff start1&lt;end2 &amp;&amp; start2&lt;end1
  Interval I1[start1, end1] is said to be within interval I2[start2,end2] iff start1&gt;start2 &amp;&amp; end1&lt;end2
  </code></pre>