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: #include<bits/stdc++.h>
using namespace std;

int longestConsecutive(vector<int>& nums)
{ int ans=0,cnt=0;
 for(int i=0;i<nums.size();i++)
 {
 	if(i==0  || nums[i-1]+1==nums[i])
 	{
 		cnt++;
 	}else cnt=1;
  ans=max(ans,cnt);
 }
 return ans;
}

int main()
{
 
 int n; cin>>n;
 int a[n];
 set<int>ss;
 for(int i=0; i<n; i++)
 { cin>>a[i];
ss.insert(a[i]);
 }
 vector<int> v;
 for(auto it:ss)
 v. push_back(it);

 cout<<longestConsecutive(v)<<endl;
 return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not?