#K93987. Longest Consecutive Subarray Length

    ID: 38541 Type: Default 1000ms 256MiB

Longest Consecutive Subarray Length

Longest Consecutive Subarray Length

This problem requires you to determine the length of the longest subarray (or subset) from a given array such that its elements can be rearranged to form a sequence of consecutive integers. In other words, you need to find a subset of the array that, when sorted, forms a sequence where each element increases by 1 from the previous one.

Formally, a sequence of consecutive integers is defined by the formula \(a, a+1, a+2, \ldots, a+(k-1)\), where \(a\) is an integer and \(k\) is the number of elements in the sequence. Your task is to output the maximum possible \(k\) for the provided array.

inputFormat

The input is read from standard input (stdin). The first line contains an integer (n) denoting the number of elements in the array. The second line contains (n) space-separated integers representing the array elements.

outputFormat

Output a single integer representing the length of the longest subarray (subset) whose elements can be rearranged to form a consecutive sequence. The output should be written to standard output (stdout).## sample

7
1 2 3 4 100 2 3
4