class Solution {
public:
int longestConsecutive(vector<int> &num) {
map<int,int> m;
int n = num.size();
for( int i = 0 ; i < n ; i++ ) {
m[num[i]] = 1;
}
for( map<int,int>::iterator itr = m.begin(); itr != m.end(); itr++ ) {
int a = itr->first;
if( m.find(a-1) != m.end() ) {
itr->second = m[a-1] + 1;
}
}
int m1 = INT_MIN;
for( map<int,int>::iterator itr = m.begin(); itr != m.end(); itr++ ) {
m1 = max(m1,itr->second);
}
return m1;
}
};
System Design for Beginners
A masterclass that helps early engineers and product managers become great at designing scalable systems.
132+ learners
Details →System Design Masterclass
A masterclass that helps you become great at designing scalable, fault-tolerant, and highly available systems.
1000+ learners
Details →Redis Internals
Learn internals of Redis by re-implementing some of the core features in Golang.
98+ learners
Details →