Given an unsorted array of integers $\text{nums}$, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in $O(n)$ time.
For example, given $[100, 4, 200, 1, 3, 2]$, the longest consecutive sequence is $[1, 2, 3, 4]$, so the answer is $4$.
This problem tests your ability to use sets cleverly. Sorting would take $O(n \log n)$, so you need a different approach.