title: How do I find the largest range of integers in a array?
body: <p>I would like to write a function that takes in an array of integers and returns an array of length 2 that represents the largest range of integers contained in that array.</p>
  <p>A range is defined as a set of consecutive numbers in the set of integers. For example, the output array <code>[2, 6]</code> represents the range <code>{2, 3, 4, 5, 6}</code>.</p>
  <p>Assume non-empty arrays and one largest range only.</p>
  <p>Sample Input: <code>array[1, 11, 3, 0, 15, 5, 2, 4, 10, 7, 12, 6]</code></p>
  <p>Sample Output: <code>[0, 7]</code></p>
  <p>The code below works for the example above but fails for the following input, for example: <code>array[8, 4, 2, 10, 3, 6, 7, 9, 1]</code> whose output should be <code>[6, 10]</code>. My code produces <code>[1, 4]</code>.
  Can someone help, please?</p>
  <pre><code>def largestRange(array):
      array.sort()
      initial = array[0]
      start_idx = initial
      final = initial
      last_idx = final
      length = 0
      size = (final - initial + 1)
  
      for i in range(1,len(array)):
          if array[i] - array[i-1] == 1 and i &lt; len(array) - 1:
              final += 1
          elif array[i] - array[i-1] == 1 and i == len(array) - 1:
              final +=1
              if size &gt; length:
                  start_idx = initial
                  last_idx = final
          else:
              if size &gt; length:
                  start_idx = initial
                  last_idx = final
                  length = size
              initial = array[i]
              final = initial
  
      return [start_idx, last_idx]
  </code></pre>
  <p>(The idea is to update the values of <code>start_idx</code> and <code>last_idx</code> everytime the sequence breaks and <code>size &gt; length</code>)</p>