#K81707. Longest Consecutive Subsequence
Longest Consecutive Subsequence
Longest Consecutive Subsequence
You are given a list of integers. Your task is to find the longest subsequence of consecutive numbers in ascending order from the provided list, regardless of the original order of elements. A subsequence is considered consecutive if for every integer (a) in the subsequence, the next integer is (a+1). For instance, given the list ( [1, 9, 3, 10, 2, 20] ), the longest consecutive subsequence is ( [1,2,3] ). In cases where the list contains multiple subsequences, output the longest one. If the input list is empty, output an empty line.
inputFormat
The first line contains an integer (T) denoting the number of test cases. Each of the following (T) lines contains a test case represented by a series of space-separated integers. An empty line represents an empty list.
outputFormat
For each test case, output a single line containing the longest consecutive subsequence (in ascending order) with each number separated by a single space. If the test case is empty, output an empty line.## sample
2
1 9 3 10 2 20
31 32 33 35 34 36 30 40
1 2 3
30 31 32 33 34 35 36
</p>