improved longest consecutive sequence (O(n))