Associated Course(s):
Geeks Classes DSA
Geeks Classes in Noida

Given an array **arr**[] of positive 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 <= 10^{5}

0 <= a[i] <= 10^{5}

**Example:**

**Input:**

2

7

2 6 1 9 4 5 3

7

1 9 3 10 4 20 2

**Output:**

6

4

**Explanation:
Testcase 1: **The consecutive numbers here are 1, 2, 3, 4, 5, 6. These 6 numbers form the longest consecutive subsquence.

**Testcase2: **1, 2, 3, 4 is the longest consecutive subsequence.

mohamadhegazy97 | 57 |

ManojBharadhwaj | 49 |

bhatabhi554 | 48 |

adityak12 | 48 |

RaghavJindal | 47 |

blackshadows | 940 |

SunkyuHwang | 794 |

bently_nixon | 701 |

mb1973 | 491 |

Shaurya Khanna | 491 |

akhayrutdinov | 5043 |

Ibrahim Nash | 4967 |

blackshadows | 4640 |

Quandray | 4354 |

sanjay05 | 3668 |

Login to report an issue on this page.