#K66867. Longest Contiguous Subarray
Longest Contiguous Subarray
Longest Contiguous Subarray
You are given an array of N integers. Your task is to find the length of the longest contiguous subarray such that when the subarray is sorted, the numbers form a contiguous sequence with no gaps. In other words, if the minimum element in the subarray is min and the maximum is max, then the subarray is valid if and only if max − min = length − 1, provided all elements in the subarray are distinct.
Input Format: The first line contains an integer N, representing the number of elements in the array. The second line contains N space-separated integers.
Output Format: Output a single integer denoting the length of the longest contiguous subarray that meets the above criteria.
Note: The contiguous subarray means a sequence of elements that appear consecutively in the original array.
inputFormat
The first line of input is an integer N (1 ≤ N ≤ 10^5). The second line contains N space-separated integers representing the array elements.
outputFormat
A single integer representing the length of the longest contiguous subarray that forms a contiguous sequence when sorted.## sample
6
10 12 11 14 13 15
6