Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5761 |

@blackshadows | 5715 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 1115 |

@bt8816103042 | 739 |

@SherlockHolmes3 | 447 |

@codeantik | 441 |

@SHOAIBVIJAPURE | 430 |

@shalinibhataniya1097 | 408 |

@ShamaKhan1 | 392 |

@neverevergiveup | 381 |

@amrutakashikar2 | 355 |

@mahlawatep | 353 |

@murarry3625 | 352 |

Complete Leaderboard |

Given an array 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.**

**Example 1:**

**Input:
**N = 7
a[] = {2,6,1,9,4,5,3}
**Output:
**6**
Explanation:
**The consecutive numbers here
are 1, 2, 3, 4, 5, 6. These 6
numbers form the longest consecutive
subsquence.

**Example 2:**

**Input:
**N = 7
a[] = {1,9,3,10,4,20,2}
**Output:
**4**
Explanation:
**1, 2, 3, 4 is the longest
consecutive subsequence.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **findLongestConseqSubseq()** which takes the array arr[] and the size of the array as inputs and returns the length of the longest subsequence of consecutive integers.

**Expected Time Complexity:** O(N).

**Expected Auxiliary Space:** O(N).

**Constraints:**

1 <= N <= 10^{5}

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

Login to report an issue on this page.

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

Yes
Longest consecutive subsequence

...