Longest streak of consecutive numbers
Given an unsorted list of integers nums, return the length of the longest streak of consecutive values x, x + 1, x + 2, … that can be formed with values from the list. The values can sit anywhere in the list, and repeats count once.
nums may be empty (the answer is then 0) and may contain negatives. Aim for O(n): no sorting.
Besides the tests, one large input (5,000 numbers) with a ~200 ms limit (scaled to your device's speed): brute force won't pass.
Examples
longest_streak([8,3,20,1,4,2])→4longest_streak([5,5,5])→1longest_streak([0,-1,7,1,-2])→4