← All problems
Longest Consecutive Sequence
Given an unsorted integer array, find the length of the longest run of consecutive integers in O(n) time. Sorting first would be O(n log n) — avoid it.
Complexity
Time O(n), Space O(n)
Common pitfalls
- Expanding from every element (O(n^2))
- Sorting first
Your solution
Log in to save your code and track progress.