#K42302. Longest Consecutive Subsequence
Longest Consecutive Subsequence
Longest Consecutive Subsequence
You are given an array of integers. Your task is to determine the length of the longest subsequence in which the integers form a consecutive sequence when sorted in ascending order. More formally, given an array ( A ), find the maximum length of a sequence ( A_{i_1}, A_{i_2}, \ldots, A_{i_k} ) (not necessarily contiguous in the original array) such that when you remove duplicates and sort the selected numbers, they form a sequence of consecutive integers.
For example, given the array [1, 3, 2, 2, 4, 3], the longest consecutive subsequence has length (4) (the subsequence would be [1, 2, 3, 4]).
Note: The input array may contain duplicates. You should consider only unique elements for forming consecutive sequences.
inputFormat
The first line contains an integer (T), representing the number of test cases. For each test case, the first line contains an integer (N), the number of elements in the array, followed by a line with (N) space-separated integers representing the array elements.
outputFormat
For each test case, output a single line containing the length of the longest consecutive subsequence.## sample
2
6
1 3 2 2 4 3
5
10 12 11 14 15
4
3
</p>