#K48612. Longest Contiguous Subarray Length

    ID: 28460 Type: Default 1000ms 256MiB

Longest Contiguous Subarray Length

Longest Contiguous Subarray Length

Given an array of integers, your task is to find the length of the longest subarray which forms a sequence of contiguous integers. In other words, after sorting the subarray, the numbers should form a consecutive sequence. Note that the subarray elements need not appear consecutively in the original array.

More formally, if you are provided with an integer \(n\) and an array \(A\) of \(n\) integers, determine the maximum length \(L\) such that there exists a subset of \(A\) with \(L\) elements where the elements can be rearranged into a sequence of consecutive integers. By definition, an empty array should yield an answer of 0.

inputFormat

The input is provided via standard input (stdin) in the following format:

  • The first line 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 to standard output (stdout), which is the length of the longest contiguous subarray.

## sample
3
10 12 11
3