Back
Longest Consecutive Sequence
Find the length of the longest consecutive elements sequence in O(n) time.
Java
Description
Solution
My Code
Longest Consecutive Sequence
Find the length of the longest consecutive elements sequence in O(n) time.
Example 1:
Input:
[100,4,200,1,3,2]
Output:
4
Viz
Tests
Run
Input
Standard
Long Chain
Empty
Custom
[100,4,200,1,3,2]
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
Variable
Value
longest
0
Depth
Function Call
Stack empty
0/39
0.5x
1x
2x
4x