Given an array of size **n**. The task is to find the longest subsequence such that absolute difference between adjacents is one. Time Complexity of O(n) is required.

Examples: Input : arr[] = {10, 9, 4, 5, 4, 8, 6} Output : 3 As longest subsequences with difference 1 are, "10, 9, 8", "4, 5, 4" and "4, 5, 6". Input : arr[] = {1, 2, 3, 2, 3, 7, 2, 1} Output : 7 As longest consecutive sequence is "1, 2, 3, 2, 3, 2, 1".

**Input:**

The first line consists of an integer **T** i.e number of test cases. The first line of each test case consists of an integer **n**.The next line consists of **n** spaced integers.

**Output:**

Print the required answer.

**Constraints: **

1<=T<=100

1<=n,a[i]<=100000

**Example:
Input:**

2

7

10 9 4 5 4 8 6

8

1 2 3 2 3 7 2 1

**Output:**

3

7

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.

saiujwal13083 | 347 |

isiddhisingh | 252 |

Abhishek_Jadhav | 243 |

_uncle_sam_ | 221 |

c_ocoooo | 217 |

saiujwal13083 | 610 |

SumitSingh27 | 466 |

c_ocoooo | 456 |

rathiarpit29 | 379 |

NaveenKumarNakka | 370 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4931 |

Quandray | 4598 |

Login to report an issue on this page.