At Stripe, event IDs may arrive out of order. Given an unsorted array of integers nums, return the length of the longest sequence of consecutive integers.
A consecutive sequence contains values that differ by 1, and the elements do not need to appear next to each other in the input array.
nums, a list of integersnumsExample 1
nums = [100, 4, 200, 1, 3, 2]4[1, 2, 3, 4].Example 2
nums = [0, 3, 7, 2, 5, 8, 4, 6, 0, 1]9[0, 1, 2, 3, 4, 5, 6, 7, 8]. Duplicate values do not extend the sequence.0 <= len(nums) <= 10^5-10^9 <= nums[i] <= 10^9O(n) average time0.nums = [100, 4, 200, 1, 3, 2]Output4WhyThe consecutive values `1, 2, 3, 4` form the longest sequence.nums = [0, 3, 7, 2, 5, 8, 4, 6, 0, 1]Output9WhyThe longest sequence is `0` through `8`, which has length `9`.nums = [10, 30, 20]Output1WhyNo two numbers are consecutive, so the longest sequence has length `1`.0 <= len(nums) <= 10^5-10^9 <= nums[i] <= 10^9Input may contain duplicate integersAim for O(n) average time complexitydef longest_consecutive(nums):