Skip to content
C

Longest Consecutive Sequence

Mediumjavapythonccppjavascript

Given an unsorted array, find the length of the longest run of consecutive integers (values differing by exactly 1), regardless of their positions in the array.

Input Format

The first line contains an integer N. The second line contains N space-separated integers.

Output Format

Print the length of the longest consecutive sequence.

Input (stdin)

Output

Run your code to see output here...