Longest Consecutive Sequence
Mediumjavapythonccppjavascript
Given an unsorted array, find the length of the longest run of consecutive integers (values differing by exactly 1), regardless of their positions in the array.
Input Format
The first line contains an integer N. The second line contains N space-separated integers.
Output Format
Print the length of the longest consecutive sequence.
Example 1
Input
6 100 4 200 1 3 2
Output
4
Explanation: The sequence 1, 2, 3, 4 has length 4.
- 1 <= N <= 100000
- -1000000000 <= A[i] <= 1000000000