We’re preparing your current view and syncing the latest data.
Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.
You must write an algorithm that runs in O(n) time.
An array of integers nums.
An integer representing the length of the longest consecutive sequence.
0 <= nums.length <= 10^5 -10^9 <= nums[i] <= 10^9
Example 1
Input
[100, 4, 200, 1, 3, 2]
Output
4
Explanation
The longest consecutive sequence is [1, 2, 3, 4], so the output is 4.