Problems / Longest Consecutive Sequence
Medium

Longest Consecutive Sequence

Medium 75 submissions 25 coins +100 XP
Array Hash Table Union Find
Problem Description
Return the length of the longest run of consecutive integers (like `4, 5, 6, 7`) whose values all appear in `nums`. The elements may be in any order. Aim for O(n). **Example 1:** ``` Input: nums = [100, 4, 200, 1, 3, 2] Output: 4 ``` **Example 2:** ``` Input: nums = [0, 3, 7, 2, 5, 8, 4, 6, 0, 1] Output: 9 ``` **Example 3:** ``` Input: nums = [] Output: 0 ```
Constraints
- `0 <= nums.length <= 10^5` - `-10^9 <= nums[i] <= 10^9`

Need help?

Connect with expert programmers for real-time collaborative coding, video meetings, and whiteboard sessions via CodeConnect.

Video Call Whiteboard Live Coding Screen Share