Leaderboard
Showing:
Handle Score
@Ibrahim Nash 5725
@blackshadows 5685
@akhayrutdinov 5111
@mb1973 4989
@Quandray 4908
@saiujwal13083 4156
@sanjay05 3762
@marius_valentin_dragoi 3511
@sushant_a 3453
@KshamaGupta 3318
@the_coder95 3302
Complete Leaderboard
Longest Consecutive Subsequence
Easy Accuracy: 42.12% Submissions: 20723 Points: 2

Given an array A of integers. Find the length of the longest sub-sequence such that elements in the sub-sequence are consecutive integers, the consecutive numbers can be in any order.
 

Example 1:

Input:
7
1 9 3 10 4 20 2
Output:
4
Explanation:
Logest consecutive subsequence is 1, 2, 3, 4 of length 4.

Example 2:

Input:
11
36 41 56 35 44 33 34 92 43 32 42
Output:
5

 

Your task:
Complete findLongestConseqSubseq() function which takes both the given array and their size as function arguments and returns the length of the longest sub-sequence such that elements in the sub-sequence are consecutive integers.

Expected Time Complexity : O(N)
Expected Auxilliary Space : O(N)

Constraints:
1 <= T <= 100
1 <= N <= 106
1 <= Ai <= 108

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Longest Consecutive Subsequence

Output Window