Longest Consecutive Sequence - aloalgo

Longest Consecutive Sequence

Hard

You are given an unsorted array of integers nums, find and return the length of the longest sequence of consecutive numbers.

Example 1

Input
[100, 4, 200, 1, 3, 2]
Output
4
Explanation:

The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4.

Example 2

Input
[0, 3, 7, 2, 5, 8, 4, 6, 0, 1]
Output
9
Explanation:

The longest consecutive elements sequence is [0, 1, 2, 3, 4, 5, 6, 7, 8]. Therefore its length is 9.

Example 3

Input
[]
Output
0
Explanation:

An empty array has no sequences, so the length is 0.

Loading...
Input
[100, 4, 200, 1, 3, 2]
Output
4

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!