meherremoff
3/12/2016 - 7:44 AM

A function called longestRun, which takes as a parameter a list of integers named L (assume L is not empty). This function returns the lengt

A function called longestRun, which takes as a parameter a list of integers named L (assume L is not empty). This function returns the length of the longest run of monotonically increasing numbers occurring in L. A run of monotonically increasing numbers means that a number at position k+1 in the sequence is either greater than or equal to the number at position k in the sequence.

def getSublists(L, n):
    return [L[i:i+n] for i in range(len(L)-n+1)]

def longestRun(L):
    master = []
    longest = 0
    for i in range(len(L)+1):
        for k in getSublists(L, i):
            master.append(k)
    for h in master:
        if sorted(h) == h and len(h) >= longest:
            longest = len(h)
    return longest

# L = [1, 2, 3, -1, -2, -3, -4, -5, -6]
# longestRun(L)