Longest Consecutive Sequence Of Elements

hard
1. You are given a number n, representing the size of array a.
2. You are given n numbers, representing elements of array a.
3. You are required to print the longest sequence of consecutive elements in the array (ignoring duplicates).

Note -> In case there are two sequences of equal length (and they are also the longest), then print the one for which the starting point of which occurs first in the array.

Input Format

A number n n1 n2 .. n number of elements

Output Format

Elements of longest sequence of consecutive elements of array in separate lines (ignoring duplicates)

Constraints

1 <= n <= 30
0 <= n1, n2, .. n elements <= 15

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
17
12
5
1
2
10
2
13
7
11
8
9
11
8
9
5
6
11
Output
5
6
7
8
9
10
11
12
13
Previous
Get Common Elements - 2
Next
Sort K-sorted Array

Related Questions