183. Longest Consecutive Sequence
MediumHash Set
Print the length of the longest run of consecutive integers (like 4, 5, 6, 7) that can be formed from the array's values, in O(n).
Input format
Line 1: n Line 2: n integers
Output format
The length.
Example 1
Input
6 100 4 200 1 3 2
Output
4
Example 2
Input
10 0 3 7 2 5 8 4 6 0 1
Output
9
Constraints
1 ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 6 test cases, most of them hidden.
Loading the MyLoginn IDE…