find the longest sequence of consecutive numbers in decreasing order I have a list [5,2,7,4,3,2,0,8, 9,100,99,98,97,93,92]
i need out [100,99,98,97]
but i am getting 4, 3, 2, 100, 99, 98, 97, 93, 92

`arr=[5,2,7,4,3,2,0,8, 9,100,99,98,97,93,92]
 z=[]
 l=[]
 for i in range(len(arr)-1):

      if(arr[i]==arr[i+1]+1):
            if(arr[i] not in z):
                z.append(arr[i])
            if(arr[i+1] not in z):
                z.append(arr[i+1])
      print(z)`
The problem with the algorithm is:
1. there is no logic that recognizes the ending of the on-going consecutive decreasing sequence.
2. there is no logic that compares candidate sequences and tracks the longer one. 

If we walk through the code, we can see it encounters a sequence of 4,3,2 starting from 4th iteration and then it encounters a sequence of 100,99,98,97. So the output is expected. 

An example of working code:

arr=[5,2,7,4,3,2,0,8, 9,100,99,98,97,93,92]
longest = []
current = []
i = 0
if len(arr &lt; 2):
    print(arr)
    return

while i &lt; len(arr)-1:
   current.append(arr[i])
   j = i + 1
   while j &lt; len(arr) and arr[i] == arr[j] + j-i:
      current.append(arr[j])
      j += 1

   i = j # start a new sequence at index j 

   if len(current) &gt; len(longest):
       longest = current
   current = []

print(longest)


There are definitely better ways to implement this in idiomatic python but hopefully, the code above illustrates the algorithm.