title: How can I find the size of the largest subset where their maximum difference is 5?
body: <p>I have an array of numbers, and I am trying to find the size of the largest subset, such that all numbers in the subset are less than 5 apart.  They can assume to be sorted, if necessary.</p>
  
  <p>For example:</p>
  
  <pre><code>[1, 2, 5, 6, 8, 9, 15]
  </code></pre>
  
  <p>4 is the largest subset. (5, 6, 8, 9)</p>
  
  <p>I expect that there is a simple LINQ answer, but I am not thinking of it.  I could sort it and then iterate through it with each starting number, keeping track of the most from that number, but that seems very ugly and inefficient.  Any ideas?</p>
  
  <hr>
  
  <p>Clarification on what I want to avoid:</p>
  
  <pre><code>(1,2,5) - 3
  (2,5,6) - 3
  (5,6,8,9) - 4
  (6,8,9) - 3
  (8,9) - 2
  (9) - 1
  (15) - 1
  </code></pre>