← problems
#128

Longest Consecutive Sequence

MediumArrays & Hashing

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

Example

nums = [100, 4, 200, 1, 3, 2]  => 4   // [1, 2, 3, 4]
Implement
function LongestConsecutive(nums: int[]) -> int

Found a bug? Or annoyed about something in the language? Tell us.

loading editor…