#K55292. Longest Consecutive Subarray
Longest Consecutive Subarray
Longest Consecutive Subarray
Given an array of integers, find the length of the longest subarray that can be rearranged to form a consecutive sequence.
A consecutive sequence is defined as a sequence of integers that can be arranged in the form:
$$a, a+1, a+2, \dots, a+k$$where each element after rearrangement differs by 1 from its adjacent element. Note that duplicates in the input array are considered only once.
For example, for the array [1, 2, 2, 3, 4, 5], the longest subarray which can be rearranged to form a consecutive sequence is [1, 2, 3, 4, 5] with a length of 5.
inputFormat
The input is given via standard input. The first line contains an integer N, representing the number of elements in the array. The second line contains N space-separated integers.
If N is 0, the array is empty.
outputFormat
Output a single integer which is the length of the longest subarray that can be rearranged to form a consecutive sequence.
## sample6
1 2 2 3 4 5
5