#K62102. Longest Contiguous Subarray
Longest Contiguous Subarray
Longest Contiguous Subarray
Given an array of integers, find the length of the longest contiguous subarray such that when the subarray is sorted, it forms a continuous sequence of integers without any duplicates.
Note: A contiguous subarray means the elements appear consecutively in the original array. After sorting the subarray, the difference between adjacent numbers should be exactly 1.
For example, if the subarray is [3, 5, 4], then after sorting it becomes [3, 4, 5] which is a contiguous sequence. However, [1, 3, 2, 2] is not allowed because of duplicate elements.
inputFormat
The input consists of two lines:
- The first line contains an integer n representing the number of elements in the array.
- The second line contains n space-separated integers representing the array elements. If n = 0, the second line may be empty.
outputFormat
Output a single integer representing the length of the longest contiguous subarray that can be rearranged into a continuous sequence of numbers with no duplicates.
## sample7
1 3 5 2 4 6 7
7