← All problems

Longest Consecutive Sequence

medium

Given an unsorted array of integers nums, return the length of the longest run of consecutive integers it contains (the numbers don't need to be adjacent in the array, just present in it). Do it in O(n) time.

Example

Input: nums = [100, 4, 200, 1, 3, 2]
Output: 4        // the run 1, 2, 3, 4
Loading...