Finding contiguous ranges in arrays