title: Set/map of sets represented as an array of ranges into an array - minimizing the size?
body: <p>I have a map of sets, say</p>
  
  <pre><code>a =&gt; {cow, dog}, b =&gt; {dog}
  </code></pre>
  
  <p>and want to store it as a map of ranges into an array, like</p>
  
  <pre><code>a =&gt; (start: 0, end: 1), b =&gt; (start: 2, end: 2) 
  [cow, dog, dog]
  </code></pre>
  
  <p>except of course </p>
  
  <pre><code>a =&gt; (start: 0, end: 1), b =&gt; (start: 1, end: 1)
  [cow, dog]
  </code></pre>
  
  <p>would be a more efficient representation. How to find the smallest solution in general? It strikes me as something that would be known to more studied people but searching yields endless pages of vaguely related stuff.</p>