HashMap & Set

Longest Consecutive Sequence

medium
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. Example: `longestConsecutive([100,4,200,1,3,2])` → `4` (`1,2,3,4`).
Hint steps(0/3 revealed)
  1. 1

    Complete previous step or reveal to unlock this hint.

  2. 2

    Complete previous step or reveal to unlock this hint.

  3. 3

    Complete previous step or reveal to unlock this hint.