s = [1, 4, 2, 3, 5, 4, 5, 6, 7, 8, 1, 3, 4, 5, 9, 10, 11, 42]
maxrun = -1
rl = {}
for x in s:
    run = rl[x] = rl.get(x - 1, 0) + 1
print(x - run + 1, 'to', x)
if run > maxrun:
    maxend, maxrun = x, run
print(list(range(maxend - maxrun + 1, maxend + 1)))
In python, how does one efficiently find the largest consecutive set of numbers in a list that are not necessarily adjacent?