Awesome Logic TC ----> O(N) and O(NLogN)
Sorting Approach--->O(NlogN) \n\nclass Solution:\n    def longestConsecutive(self, nums: List[int]) -> int:\n        nums=list(set(nums))\n        nums.sort()\n
# Sorting Approach--->O(NlogN) \n```\nclass Solution:\n    def longestConsecutive(self, nums: List[int]) -> int:\n        nums=list(set(nums))\n        nums.sort()\n        count,ans=1,0\n        for i in range(len(nums)-1):\n            if (nums[i+1]-nums[i])==1:\n                count+=1\n            else:\n                count=1\n            ans=max(ans,count)\n        return ans\n```    \n# without Sorting ------> O(N)\n```\nclass Solution:\n    def longestConsecutive(self, nums: List[int]) -> int:\n        nums=set(nums)\n        ans=0\n        for n in nums:\n            if n-1 in nums:\n                continue\n            nxt=n\n            while (nxt+1) in nums:\n                nxt+=1\n            ans=max(ans,nxt-n+1)\n        return ans\n```\n# please upvote me it would encourage me alot\n
['Binary Tree', 'Python3']