Longest Consecutive Sequence
Find the length of the longest consecutive elements sequence in O(n) time.

30:00

Longest Consecutive Sequence
medium
Topics
Companies

Find the length of the longest consecutive elements sequence in O(n) time.

Example 1:
Input: [100,4,200,1,3,2]
Output: 4
Constraints:
  • 0nums.length1050 \leq \text{nums.length} \leq 10^5

  • 109nums[i]109-10^9 \leq \text{nums}[i] \leq 10^9

Input
arr =[100,4,200,1,3,2]
Current Longest

0

Input Array
100
4
200
1
3
2
HashSet (O(1) Lookup)
100
4
200
1
3
2
Building Sequence
No active sequence
Variables
VariableValue
longest0
DepthFunction Call
Stack empty
0/39