Find the longest consecutive sequence using HashSet
📦 HashSet Elements
⛓️ Current Chain Building
Start scanning...
Checking Number
-
Current Chain Length
0
Longest Chain
0
Ready to find longest consecutive sequence
Algorithm: Only start counting from numbers where
(num-1) is NOT in set. Then expand rightward while (num+1) exists.
This ensures O(n) time complexity.