128. Longest Consecutive Sequence
Practice Longest Consecutive Sequence for free on NudgeCode: Medium, Array & Hash Table pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Given an unsorted integer array nums, return the length of the longest run of consecutive integers (like 1,2,3,4) whose values all appear in nums. The values don't have to be next to each other in the array. Aim for O(n).
Example
nums = [100,4,200,1,3,2] -> 4 (the run is 1,2,3,4)
Constraints
- 0 <= nums.length <= 10^5
- -10^9 <= nums[i] <= 10^9