Longest Consecutive Sequence Problem
Longest Consecutive Sequence Problem — ExecCode Medium DSA Practice
Solve the Longest Consecutive Sequence problem on ExecCode. Free online medium DSA practice in Hashing. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n) time.
Examples
Input nums = [100, 4, 200, 1, 3, 2, 5, 6]; Output 6. Input nums = [0, 3, 7, 2, 5, 8, 4, 6, 0, 1]; Output 9. Input nums = []; Output 0
Constraints
0 ≤ nums.length ≤ 10⁵ -10⁹ ≤ nums[i] ≤ 10⁹
Practice Longest Consecutive Sequence free on ExecCode. Browse DSA problems, topic map, and placement guides.