Longest Consecutive Sequence

Practice this coding question on Coding Gurukul.

Problem statement

An archive receives integer ticket labels in arbitrary order, sometimes with duplicates. Find the length of the longest run of consecutive distinct labels present anywhere in the archive. Their positions in the input do not matter. Aim for expected linear time.

Input format

First line: n. Second line: n space-separated integers.

Output format

Print the longest consecutive run length.

Constraints

1 <= n <= 100000; -10000 <= each value <= 10000. Use 64-bit integers for sums.

Sample input

7
12 4 10 3 11 2 4

Sample output

3

Sign in to run or submit a solution in C++, Java or Python.