Longest Consecutive Sequence

Given an unsorted array of integers, return the length of the longest consecutive elements sequence. The algorithm must run in O(n) time.

Constraints

  • 0 <= nums.length <= 100000
  • -1000000000 <= nums[i] <= 1000000000
Saving… · 2 lines
class Solution:
def longestConsecutiveSequence(self, nums: List[int]) -> int:
Console

Click Run to execute sample tests.