#K54987. Longest Contiguous Subarray

    ID: 29875 Type: Default 1000ms 256MiB

Longest Contiguous Subarray

Longest Contiguous Subarray

Given a list of integers, determine the length of the longest subarray that can be rearranged to form a consecutive sequence of integers. In other words, find the maximum length of a subarray where its elements, when sorted, form a contiguous block. Mathematically, for consecutive elements \(a_{i-1}\) and \(a_i\) in the sorted subarray, the condition \(a_i = a_{i-1} + 1\) must hold.

Note: Duplicate elements are treated as a break in the contiguous sequence, and such duplicates do not extend the length of the contiguous block (they reset the current count to 1).

inputFormat

The first line of input contains an integer n representing the number of elements in the array. The second line contains n space-separated integers.

outputFormat

Output a single integer representing the length of the longest contiguous subarray that can be rearranged to form a consecutive sequence.

## sample
5
1 2 3 5 6
3

</p>