// Function to return length of longest subsequence of consecutive integers.
int longestConsecutive(vector<int>& arr) {
// Your code here
set<int> s(arr.begin(), arr.end());
int res = 0;
for(int i=0; i<arr.size(); i++) {
if(s.find(arr[i]) != s.end() && s.find(arr[i]-1) == s.end()) {
int count = 0, cur = arr[i];
while(s.find(cur) != s.end()) {
count++;
s.erase(cur);
cur++;
}
res = max(count, res);
}
}
return res;
}