#C5479. Longest Consecutive Sequence

    ID: 49132 Type: Default 1000ms 256MiB

Longest Consecutive Sequence

Longest Consecutive Sequence

You are given a list of integers. Your task is to find and output the length of the longest consecutive sequence of integers in the array.

A consecutive sequence is a sequence of numbers where each number is exactly one more than the previous number. For example, in the list [100, 4, 200, 1, 3, 2], the longest consecutive sequence is [1, 2, 3, 4] which has length 4.

The input consists of multiple test cases. The first line of input contains a single integer T indicating the number of test cases. Each of the following T lines contains a list of space-separated integers, representing an unsorted array. For each test case, you need to compute the length of the longest consecutive elements sequence.

Note: The solution should efficiently handle duplicate numbers and unsorted arrays.

inputFormat

The input is read from standard input (stdin) and has the following format:

T
nums_1
nums_2
...
nums_T

Here, T is the number of test cases. Each nums_i is a line containing space-separated integers representing the array for that test case.

outputFormat

For each test case output one line containing the length of the longest consecutive sequence in the given array. The output should be written to standard output (stdout).

## sample
2
100 4 200 1 3 2
0 7 8 1 2 3 4 5
4

6

</p>