Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Longest Consecutive Sequence

XPChallenge Points: 20
levelLevel: Medium

You are given an unsorted integer array nums.
Your task is to find the length of the longest sequence of consecutive numbers that appear in the array.
The algorithm must run in O(n) time.
A consecutive sequence is a series of numbers that appear in increasing order without gaps (e.g., [4,5,6,7]).

Example 1:

Input: nums = [10, 5, 12, 3, 55, 4, 11, 6]

Output: 4

Example 2:

Input: nums = [15, 16, 18, 14, 19, 13, 12, 17]

Output: 8

Example 3:

Input: nums = [4, 10, 5, 6, 4, 7]

Output: 4

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result