Accepted short C++ solution, 80 ms (1 scan + 1 hash map) with explanation
1 scan solution with hash map\n\nExplanation:\n\n 1. main idea is using hash map to check previous and next element in the sequence\n 2. hash map holds length o
1 scan solution with hash map\n\nExplanation:\n\n 1. main idea is using hash map to check previous and next element in the sequence\n 2. hash map holds length of consecutive sequence for start of sequence and end of sequence\n 3. we updating that values when joining intervals\n 4. longest sequence is calculated during joining intervals\n\n          \n        int longestConsecutive(vector<int> &num) {\n            if ( num.size() < 2 ) return num.size();\n            unordered_map<int,int> m;\n            int longest = 1;\n            for ( int i: num ){\n                if ( m.find(i) != m.end() ) continue;\n                m[i] = 1;\n                if ( m.find(i-1) != m.end() ){\n                    int len = m[i] + m[i-1];\n                    m[i] = len;                            // length of sequence\n                    m[i-len+1] ++;                      // update start of range by new length of sequence\n                    longest = max( longest, len );\n                }\n                if ( m.find(i+1) != m.end() ){\n                    int len   = m[i+m[i+1]] + m[i];\n                    int start = i-m[i]+1;\n                    int end   = i+m[i+1];\n                    m[start] = len;\n                    m[end]   = len;\n                    longest = max( longest, len );\n                }\n            }\n            return longest;\n       }
['Hash Table']