No nested loops. A true O(n) time algorithm.
Approach\nUses a dictionary where each key represents a number from the input array, and its corresponding value indicates the length of a consecutive sequence 
# Approach\nUses a dictionary where each key represents a number from the input array, and its corresponding value indicates the length of a consecutive sequence with that number as either the upper or lower bound of the sequence.\n\n# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(n)$$ auxiliary space\n\n# Code\n```\nclass Solution:\n    def longestConsecutive(self, nums: List[int]) -> int:\n        nums = set(nums)\n        table = {}\n        maxval = 0\n        for num in nums:\n            x = table.get(num - 1, 0)\n            y = table.get(num + 1, 0)\n            val = x + y + 1\n            table[num - x] = val\n            table[num + y] = val\n            maxval = max(maxval, val)\n        return maxval\n\n```
['Python3']