Search⌘ K
AI Features

Problem: Longest Consecutive Sequence

Explore how to determine the longest consecutive sequence in an unsorted array using a hash set for O(1) lookups. Learn to optimize your solution by identifying sequence starts and traversing consecutively, achieving overall O(n) time and space complexity. This lesson builds your problem-solving skills with hash tables in Java.

Statement

Given an unsorted array of integers nums, determine the length of the longest sequence of consecutive elements that can be formed from the values in the array.

Your solution must operate in O(n)O(n) time complexity.

Constraints:

  • 00 \leq nums.length 105\leq 10^5 ...