New update is available. Click here to update.

Last Updated: 28 Sep, 2020

Difficulty: Moderate

```
If there are any duplicates in the given array we will count only one of them in the consecutive sequence.
```

```
For the given 'ARR' [9,5,4,9,10,10,6].
Output = 3
The longest consecutive sequence is [4,5,6].
```

```
Can you solve this in O(N) time and O(N) space complexity?
```

```
The first line of input contains a single integer 'T', representing the number of test cases or queries to be run. Then the 'T' test cases follow.
The first line of each test case contains integer 'N' denoting the size of the array.
The second line of each test case contains 'N' single space-separated integers, elements of the array.
```

```
For each test case, print an integer in a single line that represents the length of the longest consecutive sequence.
```

```
You are not required to print the expected output; it has already been taken care of. Just implement the function.
```

```
1 <= T <= 10
1 <= N <= 10^5
-10^9 <= ARR[i] <= 10^9
Time Limit: 1 sec
```

SIMILAR PROBLEMS

Longest Subarray With Zero Sum

Posted: 3 Nov, 2022

Difficulty: Moderate

Merge Two Sorted Arrays Without Extra Space

Posted: 19 Nov, 2022

Difficulty: Moderate

Ninja And The Strictly Increasing Array

Posted: 27 Nov, 2022

Difficulty: Moderate

Negative To The End

Posted: 16 Dec, 2022

Difficulty: Easy

Sort 0s, 1s, 2s

Posted: 24 Dec, 2022

Difficulty: Easy

Popular Interview Problems: