← All problems

Longest Consecutive Sequence

Medium hash mapsarraysunion-find LeetCode ↗
Given an unsorted integer array, find the length of the longest run of consecutive integers in O(n) time. Sorting first would be O(n log n) — avoid it.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n), Space O(n)

Common pitfalls

  • Expanding from every element (O(n^2))
  • Sorting first

Your solution

Log in to save your code and track progress.