title: Rowspan "clean-up" algorithm
body: <p>I have a structure, that resembles HTML table's colspan/rowspan feature:</p>
  
  <pre><code>[
   [1,4], [4,1]
   [2,2], [2,2]
   [1,1], [1,1], [1,1], [1,1]
  ]
  </code></pre>
  
  <p>is like </p>
  
  <pre><code>&lt;tr&gt;
    &lt;td rowspan=4&gt;&lt;/td&gt;
    &lt;td colspan=4&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td rowspan=2 colspan=2&gt;&lt;/td&gt;
    &lt;td colspan=2 rowspan=2&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;/td&gt;
    &lt;td&gt;&lt;/td&gt;
    &lt;td&gt;&lt;/td&gt;
    &lt;td&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  ----------------
  |  |           |
  |  |-----------|
  |  |     |     |
  |  |-----------|
  |  |  |  |  |  |
  ----------------
  </code></pre>
  
  <p>The second row (and the first cell from the first row, that spans all 4 rows) in</p>
  
  <pre><code>[
   [1,3], [4,1]
   [2,1], [2,1]
   [1,1], [1,1], [1,1], [1,1]
  ]
  </code></pre>
  
  <p>and "topology" of the table remains the same</p>
  
  <p>However a table like</p>
  
  <pre><code>[
   [1,4], [4,1]
   [2,2], [2,1]
   [2,1],
   [1,1], [1,1], [1,1], [1,1]
  ]
  
  ----------------
  |  |           |
  |  |-----------|
  |  |     |     |
  |  |     |-----|
  |  |     |     |
  |  |-----------|
  |  |  |  |  |  |
  ----------------
  </code></pre>
  
  <p>is not "collapsible"</p>
  
  <p>What is an effecient algorithm to perform this transformation or leave the table as is? Any programming language would work.</p>
  
  <p>Assume, that the structure is valid (not missing cells, the table is rectangular) if it simplifies the task</p>