Arrays & HashingMedium

Longest Consecutive Sequence

Return the length of the longest run of consecutive whole numbers you can make from nums (like 4, 5, 6, 7), in O(n) time. The numbers can be in any order in the list.

Example 1nums = [9, 1, 4, 7, 3, -1, 0, 5, 8, 6] → 73 through 9.
Example 2nums = [] → 0
0 ≤ n ≤ 10⁵ · −10⁹ ≤ nums[i] ≤ 10⁹

Hints

0 of 3 open
Hint 2 · the patternHint 3 · the key line