😍 Simplest Python solution with O(n) time complexity and O(n) space complexity
Intuition\n Describe your first thoughts on how to solve this problem. \nPython solution with a simple algorithm to find solution in O(n) time complexity with O
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nPython solution with a simple algorithm to find solution in O(n) time complexity with O(n) space complexity. \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Convert list to set using inbuilt set function.\n2. Create low and high integer to store low and high values in ongoing sequence and assign low and high value to current value.\n3. Run a while loop that continues till high + 1 or low - 1 is present in uniques set.\n    * If `low - 1` is present in uniques, decrease value of low by 1, and remove `low - 1` element from uniques.\n    * If `high + 1` is present in uniques, increase value of high by 1. and remove `high + 1` element from uniques.\n4. As we keep on iterating, we will be left with empty set, thus stopping our while loop.\n\n> Note that **in** operator in case of set has a time complexity of O(1) only.\n\n# Complexity\n- Time complexity: O(n)\n- Space complexity: O(n)\n\n# Code\n```python3\nclass Solution:\n    def longestConsecutive(self, nums: List[int]) -> int:\n        uniques = set(nums)\n        max_length = 0\n\n        while uniques:\n            low = high = uniques.pop()\n            \n            while low - 1 in uniques or high + 1 in uniques:\n                if low - 1 in uniques:\n                    uniques.remove(low - 1)\n                    low -= 1\n                \n                if high + 1 in uniques:\n                    uniques.remove(high + 1)\n                    high += 1\n\n            max_length = max(high - low + 1, max_length)\n\n        return max_length\n```
['Python3']