dsa · medium
Longest Consecutive Sequence
GreyOrangeArrayHash Set
Return the length of the longest consecutive-elements sequence in nums (unsorted). O(n) expected.
Arguments
nums— the input array of integers
**Example:** [100,4,200,1,3,2] → 4 (1,2,3,4).
Constraints
0 <= nums.length <= 4*10^4 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [100,4,200,1,3,2] Expected: 4
Example 2
Input: [0,3,7,2,5,8,4,6,0,1] Expected: 9