Longest Consecutive Subsequence
Submissions: 11836   Accuracy:


  Difficulty: Easy   Marks: 2

Given an array A of integers. The task is to complete the function which returns an integer denoting the length of the longest sub-sequence such that elements in the sub-sequence are consecutive integers, the consecutive numbers can be in any order.

The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains an integer N. Then in the next line are N space separated values of the array A.

For each test case in a new line output will be the length of the longest consecutive increasing sub-sequence present in the array A[ ].

1 <= T <= 100
1 <= N <= 106
1 <= Ai <= 108

Example(To be used only for expected output):

1 9 3 10 4 20 2
36 41 56 35 44 33 34 92 43 32 42

Testcase 1:
Logest consecutive subsequence is 1, 2, 3, 4 of length 4.

Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Harshit Sidhwa, Amit Khandelwal
Author: Shubham Joshi 1

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.