#K1276. Longest Contiguous Subarray
Longest Contiguous Subarray
Longest Contiguous Subarray
Problem Statement: Given an array of integers, find the length of the longest subarray that forms a contiguous sequence. A contiguous sequence means that, when the numbers in the subarray are considered as a set, they form a sequence of consecutive numbers with a common difference of 1. The numbers in the subarray do not need to be in sorted order originally, but duplicates are ignored when determining the sequence.
For example, the subarray [1, 9, 3, 10, 4, 20, 2] has a contiguous sequence of {1, 2, 3, 4} which has a length of 4.
Note: The input array may contain duplicates. In forming the contiguous sequence, each number is considered only once.
inputFormat
Input is given via standard input (stdin). 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 that forms a consecutive sequence.## sample
7
1 9 3 10 4 20 2
4