Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <bits/stdc++.h>
using namespace std;
int findSequence(vector<int> v) {
unordered_set<int> hashSet;
for(auto i = v.begin(); i != v.end(); i++) {
hashSet.insert(*i);
}
int length = 0;
int max = 0;
for(auto i = v.begin(); i != v.end(); i++) {
if (hashSet.find(*i - 1) != hashSet.end()) {
continue;
}
int start = *i;
while (hashSet.find(start++) != hashSet.end()) {
length++;
}
if (length > max) {
max = length;
length = 0;
}
}
return max;
}
int main() {
vector<int> v = {1,4,5,6,3};
cout << findSequence(v) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.