1def longest_consecutive(nums):2    ns = set(nums)3    max_streak = 04    for n in nums:5        if (n - 1) not in ns:6            streak = 17            while n + streak in ns:8                streak += 19            max_streak = max(max_streak, streak)10    return max_streak