For this Question: Given an unsorted array of integers, find the length of the longest consecutive elements sequence.

A consecutive set of integers is a consecutive elements sequence.

See sample for better understandingFirst line contains integer N number of elements of the array. Next line contains N space separated integers which are elements of array.
Constraints
1<= N <=100000
1<= A[i] <=100000Output the longest consecutive sequence in the array.Sample Input
7
100 4 200 1 3 2 2

Sample Output
4

Explanation
The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4., I have written this Solution Code: import java.io.*;
import java.util.*;



class Main {
	public static void main (String[] args) throws IOException {

		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		Set<Integer> set=new TreeSet<>();
		String nums[]=br.readLine().split("\\s+");
		try
		{
		for(int i=0;i<n;++i)
		{
			set.add(Integer.parseInt(nums[i]));
		}
		}catch(NumberFormatException e)
		{}
		int max=0;
		int prev=0;
		int count=1;
		for(Integer i:set)
		{
			if(prev==0)
			{
				prev=i;
				continue;
			}
			if(prev+1==i)
			{
				++count;
			}
			else
			{
				if(count>max) max=count;
				count=1;
			}
			prev=i;
		}
		if(count>max) max=count;
		System.out.println(max);
	}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?