Skip to content

Instantly share code, notes, and snippets.

@javi830810
Created October 9, 2020 00:31
Show Gist options
  • Save javi830810/d5a12553bed773c46b71f662e85c4b60 to your computer and use it in GitHub Desktop.
Save javi830810/d5a12553bed773c46b71f662e85c4b60 to your computer and use it in GitHub Desktop.
def find_longest_sequence(arr):
start = 0
seq_result = []
def sum_array(arr):
_sum = 0
for x in arr:
_sum += x
return _sum
if len(arr) == 1:
return arr
for x in xrange(0,len(arr)):
_max = arr[x]
_min = arr[x]
seq = []
for y in xrange(x,len(arr)):
seq.append(arr[y])
_min = min(arr[y],_min)
_max = max(arr[y],_max)
if len(seq) == 1:
continue
result_sum = sum_array(seq)
if result_sum + (_min-1)*_min/2 == _max*(_max+1)/2:
if not seq_result or len(seq_result) < len(seq):
seq_result = seq[:]
return seq_result
a = [20,19,12,10,7,4,1,6,5,3,2,90,49]
print find_longest_sequence(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment