Python program to Longest ordered Sequence in Ascending Order

from random import random
num = 20
listitem = [0]*num
for i in range(num):
 listitem[i] = int(random()*50)
print(listitem)
maxi = 1
mylength = 1
mycode = 0
for i in range(1,num):
 if listitem[i] > listitem[i-1]:
    mylength += 1
 else:
    if mylength > maxi:
     maxi = mylength
     mycode = i
 mylength = 1
print("The maximum length = ",maxi)
print("The ordered values are = ",listitem[mycode-maxi : mycode])

 

 

 

Output:

[41, 14, 8, 4, 46, 43, 40, 5, 25, 15, 5, 21, 22, 40, 49, 5, 0, 20, 6, 6]
The maximum length =  1
The ordered values are =  []

 

Subscribe For Daily Updates