How to find the longest substring by order of frequency?
<p>This is best described with an example.  Given the paragraph:</p>

<p><code>The longest string in this paragraph is not the shortest string in the paragraph because it is the longest string in the paragraph</code></p>

<p>I want to list the order of matching sub-strings first by frequency and then by length, so in this case, it should list (non case-sensitive)</p>

<ul>
<li><code>The longest string in</code></li>
<li><code>the paragraph</code></li>
<li><code>is not the shortest string in</code></li>
<li><code>because</code></li>
<li><code>it is</code></li>
<li><code>this</code></li>
</ul>

<p>The above lists the substrings by the order of frequency they occur, followed by length, so <code>The longest string in</code> is repeated twice and is the longest substring.  <code>is not the shortest string in</code> is longer than <code>the paragraph</code>, but <code>the paragraph</code> is repeated twice, so it is listed first.</p>

<p>Update(based on observation by AlexC and MattBurland):</p>

<p>Even if a sub-string such as the space character or <code>in</code> occur more than other substrings, they should not be listed if they are already included in a substring that is longer than their occurrence * length.  For example,  <code>in</code> occurs 3 times which is 6 characters in length (9 including spaces at the end), but since 9 characters is shorter than <code>the paragraph</code>, it is not listed.  I hope this makes sense?</p>
