Search⌘ K
AI Features

Problem: Longest Consecutive Sequence

Discover how to determine the length of the longest consecutive integer sequence in an unsorted array using hash tables in Go. Learn to implement an efficient O(n) solution by leveraging hash-based lookups to avoid redundant checks. This lesson guides you through creating a set for quick membership testing, identifying sequence starts, and expanding sequences to find maximum lengths, improving your understanding of hash tables and time complexity optimization.

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 ...