Longest Consecutive Subsequence

easy
1. Given an array arr[] of positive integers. 2. 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 Format

First line contains N(size of the array). Second line contains n space separated integers.

Output Format

Return the largest length.

Constraints

1 <= N <= 10^5
 0 <= a[i] <= 10^5

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
7
2 6 1 9 4 5 3
Output
6
Previous
Logger Rate Limiter
Next
Longest Harmonious Subsequence

Related Questions