dsa6 min read
Longest Consecutive Sequence — HashSet O(n) with Amortized Analysis [LC 128]
LeetCode 128 — asked at Google, Amazon, and Meta. Find the longest consecutive integer sequence in O(n) using a HashSet. Only start counting from numbers where num-1 is absent — each element is visited at most twice total, making an apparent O(n²) nested loop amortized O(n).
Read →