Return the length of the longest set of values in nums that are consecutive whole numbers such as 4, 5, 6, 7. The values can appear anywhere and in any order, and repeats count once. An empty list gives 0.
Sorting works in O(n log n). See if you can do it in O(n).
Example 1
Input:
longest_consecutive([100, 4, 200, 1, 3, 2])
Output:
4
1, 2, 3, 4 is the longest run.
Example 2
Input:
longest_consecutive([5, 5, 5])
Output:
1
Repeats count once.
0 <= len(nums) <= 2 * 10**5-10**9 <= nums[i] <= 10**9No results yet
Run your code to check it against the examples, or submit to run every test.