Longest consecutive subsequence
Submissions: 9839   Accuracy:

48.09%

  Difficulty: Medium   Marks: 4
Associated Course(s):   Sudo Placement [IITs]
     

Given an array of integers, find the length of the longest sub-sequence such that elements in the subsequence are consecutive integers, the consecutive numbers can be in any order.

Input:

The first line of input contains T, number of test cases.

First line of line each test case contains a single integer N.

Next line contains N integer array.

Output:

Print the output of each test case in a seprate line.

Constraints:

1<=T<=100
1<=N<=100
0<=a[i]<=500

Example:

Input:

2
7
2 6 1 9 4 5 3
7
1 9 3 10 4 20 2

Output:

6
4

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

Author: bhawnamait


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

to report an issue on this page.