13-line C++ solution
Thought I would share it here. May be useful for some one. The algorithm itself is pretty straightforward. But it benefited quite much from the neat expression 
Thought I would share it here. May be useful for some one. The algorithm itself is pretty straightforward. But it benefited quite much from the neat expression of C++ idioms. Comments are appreciated!\n\n    int longestConsecutive(const vector<int> &num) {\n        unordered_set<int> s(num.begin(), num.end()), searched;\n        int longest = 0;\n        for (int i: num) {\n            if (searched.find(i) != searched.end()) continue;\n            searched.insert(i);\n            int j = i - 1, k = i + 1;\n            while (s.find(j) != s.end()) searched.insert(j--);\n            while (s.find(k) != s.end()) searched.insert(k++);\n            longest = max(longest, k - 1 - j);\n        }\n        return longest;\n    }
[]