Longest subsequence-1
Submissions: 4420   Accuracy:

33.57%

  Difficulty: Easy   Marks: 2

Given an array A of size N, the task is to find the longest subsequence such that difference between adjacents is one.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains an integer N denoting the size of array A.
The second line of each test case contains N space separated integers denoting elements of the array A[ ].

Output:
For each testcase, in a new line, print the length of the longest subsequence such that difference between adjacents is one.

Constraints:
1<= T <=100
1<= N <=103
1<= A[ ] <=103

Example:
Input:
1
7
10 9 4 5 4 8 6
Output:
3

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

Contributor: Sujnesh Mishra
Author: sujnesh


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.