Longest Consecutive Sequence Store all items in a hash set Go through each item in the hash set If the item is the begining of a sequence look for remaining items def longest(nums): items = set(nums) maxsize = 0 for item in items: if (item - 1) not in items: length = 1 while (current + length) in items: length += 1 maxsize = max(maxsize, length) return maxsize def pr(ok): print("Ok" if ok else "Error") pr(4 == longest([100, 4, 200, 1, 3, 2])) pr(9 == longest([0, 3, 7, 2, 5, 8, 4, 6, 0, 1]))