Longest consecutive run
Mediumarrayhash set
Given unsorted numbers, return the length of the longest run of consecutive values (like 4, 5, 6, 7) among them, in O(n).
Example 1
Input: nums = [100,4,200,1,3,2] Output: 4
The run 1, 2, 3, 4.
Example 2
Input: nums = [0,3,7,2,5,8,4,6,0,1] Output: 9
Constraints
- 0 ≤ nums.length ≤ 10⁵
- -10⁹ ≤ nums[i] ≤ 10⁹
Submit checks your solution against 8 tests, including hidden ones.
/**
* @param {int[]} nums
* @return {int}
*/
function longestConsecutive(nums) {
}