Back to exercises

Longest Consecutive Sequence

Put all numbers in a set, then expand sequences only from values whose previous number is absent. That avoids re-counting the same streak multiple times.

Coding Exercises Medium O(n)

Longest Consecutive Sequence

Put all numbers in a set, then expand sequences only from values whose previous number is absent. That avoids re-counting the same streak multiple times.

Return the length of the longest consecutive sequence in an unsorted array.