How to count the maximum consecutive set of numbers in a list with Python

1 Answer

0 votes
def countMaxConsecutiveSetOfNumbers(lst) :
    size = len(lst)
    st =  set()
    
    i = 0
    while (i < size) :
        st.add(lst[i])
        i += 1
    
    mx = 0
    i = 0
    while (i < size) :
        if (lst[i] in st) :
            temp = lst[i]
            while (temp in st) :
                temp += 1
            mx = max(mx,temp - lst[i])
        i += 1
    
    return mx

lst = [22, 3, 21, 32, 24, 31, 4, 99, 23]

# 21 22 23 24

print(countMaxConsecutiveSetOfNumbers(lst))



'''
run:

4

'''

 



answered Oct 22, 2022 by avibootz
...