Range Simplification in Java
<p>I have a Range object which consists of a min and a max. Hence, there can be ranges such as</p>

<pre><code>[1, 5]
[6, 12]
[13, 14]
</code></pre>

<p>Here's my question. Suppose you have a list of ranges given by</p>

<pre><code>ArrayList&lt;Range&gt; ranges;
</code></pre>

<p>and you want to fix them so that there are no overlapping ranges. That is, there are two functions:</p>

<pre><code>public void addRange(Range r);

public void removeRange(Range r);
</code></pre>

<p>You may assume that after each method, the <code>ranges</code> ArrayList will always be sorted by the min value. Note that the <code>ranges</code> ArrayList always contains an initial range of <code>[1, 100]</code>. Here are some examples with <code>ranges</code> before and after:</p>

<pre><code>ranges = {[1,5], [6,12], [13,14]}
addRange([7, 15])
ranges = {[1,5], [6,15]}

ranges = {[1,12], [18,29], [34,89]}
addRange([16,17])
ranges = {{[1,12], [16,17], [18,29], [34,89]}

ranges = {[16,35]}
removeRange([19,54])
ranges = {[16,19]}
</code></pre>

<p>How can I write these two functions?</p>
