Example 1
Input
longest_consecutive([100, 4, 200, 1, 3, 2])
Output
4
The longest consecutive sequence is [1, 2, 3, 4], so the length is 4.
Full lesson preview
Given an unsorted list of integers, find the length of the longest run of consecutive integers. Use hashing for O(n) time.
Problem statement
Task
Examples
Input
longest_consecutive([100, 4, 200, 1, 3, 2])
Output
4
The longest consecutive sequence is [1, 2, 3, 4], so the length is 4.
Input format
Output format
Constraints
Samples
Input
[100, 4, 200, 1, 3, 2]
Output
4
Longest run is [1,2,3,4] -> length 4